Posted By

emoseman on 10/16/08


Tagged

textmate query Oracle cursor


Versions (?)

Oracle Cursor Query


 / Published in: Other
 

  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  

You need to login to post a comment.