[英]How to call stored procedure using Weblogic data source connection?
我有使用weblogic数据源连接调用已编译的sql存储过程的请求吗?
有什么解决办法吗?
感谢您的回复,我找到了解决方案。
我们可以使用以下代码:
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();
}
}
}
这解决了我的问题。
我希望它也会对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.