简体   繁体   中英

Get ResultSet from Stored Procedure in Oracle from Java

I've been looking through many posts in the forum related to my problem but I nothing helped me, so I'm posting my problem. I have a SP in Oracle (11g) that is suppossed to return a Result Set. The SP looks like follows:

CREATE OR REPLACE
PROCEDURE testProc
(
  tableName IN VARCHAR2,
  INFORMATION OUT SYS_REFCURSOR
) AS 
  sqlQuery varchar2(1000);
BEGIN
  sqlQuery := 'SELECT ID||''|''||Name||''|''||Surname FROM '||tableName;
  OPEN INFORMATION FOR sqlQuery;
END GETVALIDATIONPECLOG;

And the way I'm calling it from java is

...
CallableStatement cs = null 
cs = connection.prepareCall("{call getvalidationpeclog(?,?)}");
cs.setString(1, table);
cs.registerOutParameter(2, OracleTypes.CURSOR);
System.out.println("AS: " + cs.execute()); //Returns false
rs = (ResultSet) cs.getObject(2);
while (rs.next()) {
   bw.write(rs.getString(1));
   bw.newLine();
}
...

but guess what? It doesn't work at all... What am I missing? Thanks !

OK. Sorry my fault. I wasn't closing the BufferedWriter... That code works really fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM