/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(Extracted from http://asktom.oracle.com/tkyte/ResultSets/) import java.sql.*; import java.io.*; import oracle.jdbc.driver.*; class curvar { public static void main (String args []) throws SQLException, ClassNotFoundException { String driver_class = "oracle.jdbc.driver.OracleDriver"; String connect_string = "jdbc:oracle:thin:@slackdog:1521:oracle8"; String query = "begin :1 := sp_listEmp; end;"; Connection conn; Class.forName(driver_class); conn = DriverManager.getConnection(connect_string, "scott", "tiger"); CallableStatement cstmt = conn.prepareCall(query); cstmt.registerOutParameter(1,OracleTypes.CURSOR); cstmt.execute(); ResultSet rset = (ResultSet)cstmt.getObject(1); while (rset.next ()) System.out.println( rset.getString (1) ); cstmt.close(); } }