【Java 调用Oracle 存储过程】
2013-09-17 09:20
417 查看
用java编写调用带返回结果集存储过程:
[java]
/**
* 调用带返回结果集存储过程
*
* @param procName
* @param param
* @return
* @throws SQLException
* @throws NoFreeConnectionException
*/
public DataSource execuceProc(String procName, String[] param) throws SQLException, NoFreeConnectionException {
Connection con = null;
CallableStatement getResults = null;
ResultSet rs = null;
StringBuffer build = new StringBuffer();
build.append("{ call ")。append(procName);
build.append("(");
if (param != null && param.length > 0) {
for (int i = 0; i < param.length; i++) {
build.append("'")。append(param[i])。append("',");
}
}
build.append("?) }");
try {
con = ConnectDBBean.getConnection(ReadWriteDBPool.readPool);
getResults = con.prepareCall(build.toString(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
getResults.registerOutParameter(1, OracleTypes.CURSOR);
getResults.execute();
rs = (ResultSet) getResults.getObject(1);
this.rsToDataSource(rs);
} finally {
try {
if (rs != null) {
rs.close();
}
if (getResults != null) {
getResults.close();
}
} catch (SQLException e) {
log.error(e);
}
ConnectDBBean.closeConnection(ReadWriteDBPool.readPool, con);
}
return new DataSourceType();
<STRONG> }</STRONG>
/**
* 调用带返回结果集存储过程
*
* @param procName
* @param param
* @return
* @throws SQLException
* @throws NoFreeConnectionException
*/
public DataSource execuceProc(String procName, String[] param) throws SQLException, NoFreeConnectionException {
Connection con = null;
CallableStatement getResults = null;
ResultSet rs = null;
StringBuffer build = new StringBuffer();
build.append("{ call ")。append(procName);
build.append("(");
if (param != null && param.length > 0) {
for (int i = 0; i < param.length; i++) {
build.append("'")。append(param[i])。append("',");
}
}
build.append("?) }");
try {
con = ConnectDBBean.getConnection(ReadWriteDBPool.readPool);
getResults = con.prepareCall(build.toString(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
getResults.registerOutParameter(1, OracleTypes.CURSOR);
getResults.execute();
rs = (ResultSet) getResults.getObject(1);
this.rsToDataSource(rs);
} finally {
try {
if (rs != null) {
rs.close();
}
if (getResults != null) {
getResults.close();
}
} catch (SQLException e) {
log.error(e);
}
ConnectDBBean.closeConnection(ReadWriteDBPool.readPool, con);
}
return new DataSourceType();
}
[java]
/**
* 调用带返回结果集存储过程
*
* @param procName
* @param param
* @return
* @throws SQLException
* @throws NoFreeConnectionException
*/
public DataSource execuceProc(String procName, String[] param) throws SQLException, NoFreeConnectionException {
Connection con = null;
CallableStatement getResults = null;
ResultSet rs = null;
StringBuffer build = new StringBuffer();
build.append("{ call ")。append(procName);
build.append("(");
if (param != null && param.length > 0) {
for (int i = 0; i < param.length; i++) {
build.append("'")。append(param[i])。append("',");
}
}
build.append("?) }");
try {
con = ConnectDBBean.getConnection(ReadWriteDBPool.readPool);
getResults = con.prepareCall(build.toString(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
getResults.registerOutParameter(1, OracleTypes.CURSOR);
getResults.execute();
rs = (ResultSet) getResults.getObject(1);
this.rsToDataSource(rs);
} finally {
try {
if (rs != null) {
rs.close();
}
if (getResults != null) {
getResults.close();
}
} catch (SQLException e) {
log.error(e);
}
ConnectDBBean.closeConnection(ReadWriteDBPool.readPool, con);
}
return new DataSourceType();
<STRONG> }</STRONG>
/**
* 调用带返回结果集存储过程
*
* @param procName
* @param param
* @return
* @throws SQLException
* @throws NoFreeConnectionException
*/
public DataSource execuceProc(String procName, String[] param) throws SQLException, NoFreeConnectionException {
Connection con = null;
CallableStatement getResults = null;
ResultSet rs = null;
StringBuffer build = new StringBuffer();
build.append("{ call ")。append(procName);
build.append("(");
if (param != null && param.length > 0) {
for (int i = 0; i < param.length; i++) {
build.append("'")。append(param[i])。append("',");
}
}
build.append("?) }");
try {
con = ConnectDBBean.getConnection(ReadWriteDBPool.readPool);
getResults = con.prepareCall(build.toString(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
getResults.registerOutParameter(1, OracleTypes.CURSOR);
getResults.execute();
rs = (ResultSet) getResults.getObject(1);
this.rsToDataSource(rs);
} finally {
try {
if (rs != null) {
rs.close();
}
if (getResults != null) {
getResults.close();
}
} catch (SQLException e) {
log.error(e);
}
ConnectDBBean.closeConnection(ReadWriteDBPool.readPool, con);
}
return new DataSourceType();
}
相关文章推荐
- Java 调用Oracle 存储过程
- java 调用存储过程-oracle
- 结合oracle中的存储过程,在Java中调用并测试该存储过程
- java调用Oracle用户登录存储过程
- Java调用Oracle分页存储过程
- JAVA 调用Oracle 及存储过程
- 游标、例外、存储过程、存储函数、java调用存储过程、触发器(Oracle之二)
- Oracle创建存储过程以及JAVA调用方法
- Java如何实现调用oracle带有返回值的存储过程
- java中调用存储过程(oracle)
- 怎样在java代码中调用Oracle的存储过程
- java调用Oracle中的存储过程
- java 调用Oracle 存储过程(SpringBoot下的事务管理)
- oracle 存储过程编写和java程序调用oracle存储过程
- 触发器,存储过程,oracle调用java方法
- java调用ORACLE 存储过程返回值
- Java 开发中之七:oracle中的子程序之在JAVA中如何调用存储过程,函数。
- java调用ORACLE 存储过程返回值22
- java调用oracle含输入和输出数组的存储过程
- java调用ORACLE 存储过程返回值33