I have a request to call compiled sql stored procedure using weblogic data source connection ?
Have any solution for that ?
The following oracle documentation should point you in the right direction:
Configuring and Managing WebLogic JDBC
I have made the assumption that you are using Oracle and not SQL Server.
Thanks for your response , I have found the solution.
We can use code below:
private void callStoreProcedure() {
Context ctx = null;
Connection conn = null;
ResultSet rs = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try {
ctx = new InitialContext(ht);
DataSource ds = (DataSource) ctx.lookup("wl_datasouce");
conn = ds.getConnection();
CallableStatement cstmt = conn.prepareCall("{call procedure(?)}");
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
cstmt.executeUpdate();
rs = (ResultSet)cstmt.getObject(1);
// print the results
while (rs.next()) {
System.out.println(rs.getInt(1) + "\t" +
rs.getString(2) + "\t" +
rs.getString(3));
}
} catch (Exception e) {
// a failure occurred log message;
e.printStackTrace();
}finally {
//cstmt.close();
try {
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
conn = null;
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This has resolved my problem.
I hope it will help others too.
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.