您的位置:首页 > 数据库 > Oracle

java调用oracle函数

2015-06-11 15:20 453 查看
/**
* 调用函数取得数据表的ID值
* @param tableName 表名
* @return
* @throws SQLException
*/
public String callFun(String tableName) throws SQLException {
Connection conn = ConnectionFactory.getConnection();
CallableStatement cstmt = null;
cstmt = conn.prepareCall("{?=call getIdBySeq(?)}");
cstmt.registerOutParameter(1, Types.VARCHAR);
cstmt.setString(2, tableName);
cstmt.execute();
return cstmt.getString(1);
}

public class ConnectionFactory {

private ConnectionFactory() {
}

private static ComboPooledDataSource ds = null;

public static synchronized Connection getConnection() {
Connection con = null;
ds = new ComboPooledDataSource();
try {
con = ds.getConnection();
} catch (SQLException e1) {
e1.printStackTrace();
}
return con;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: