Oracle Cursor Query


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. (Extracted from http://asktom.oracle.com/tkyte/ResultSets/)
  2. import java.sql.*;
  3. import java.io.*;
  4. import oracle.jdbc.driver.*;
  5.  
  6.  
  7. class curvar
  8. {
  9. public static void main (String args [])
  10. throws SQLException, ClassNotFoundException
  11. {
  12. String driver_class = "oracle.jdbc.driver.OracleDriver";
  13. String connect_string = "jdbc:oracle:thin:@slackdog:1521:oracle8";
  14.  
  15. String query = "begin :1 := sp_listEmp; end;";
  16. Connection conn;
  17.  
  18. Class.forName(driver_class);
  19. conn = DriverManager.getConnection(connect_string, "scott", "tiger");
  20.  
  21. CallableStatement cstmt = conn.prepareCall(query);
  22. cstmt.registerOutParameter(1,OracleTypes.CURSOR);
  23. cstmt.execute();
  24. ResultSet rset = (ResultSet)cstmt.getObject(1);
  25.  
  26. while (rset.next ())
  27. System.out.println( rset.getString (1) );
  28. cstmt.close();
  29. }
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.