Tags

,

links:
http://www.coderanch.com/t/301282/JDBC/databases/Calling-Oracle-functions
http://www.ibm.com/developerworks/data/library/techarticle/dm-1209storedprocedures/index.html

summary:
– ResultSet rs = stmt.executeQuery(“{call GETCUSTNAME}”);
while (rs.next()) { blah blah }
rs.close();
stmt.close();

– procedure example:
sqlst = “{ call sp_get_some_back(?,?) }”; // {} or not still ok?
call = conn1.prepareCall(sqlst);
call.setString(1, req_id);
call.registerOutParameter(2, java.sql.Types.INTEGER);
callableExec(conn1, call);
count = call.getInt(2);

– function example:
//db is my database connection object
String funct = “{ ? = ci_publish_client_data(?) }”;
CallableStatement cs = db.prepareCall(funct);
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.setInt(2, Integer.parseInt(1234));
cs.execute();
return cs.getObject(1);

– Statement, no IN nor OUT parm (stored procedure)
– PreparedStatement, w/ IN but no OUT (stored procedure)
– CallableStatement, both IN and OUT (stored procedure)

Advertisements