我有一个配置了连接池的数据源可供使用,它通过JDNI公开给我的应用程序,但我的同事编写的代码实际上打开并关闭每个查询的连接。 WSO2如何处理这个问题?它是否真的关闭了池提供的连接,或者忽略了关闭,只是认为这个连接可以自由地添加回池中并准备好被其他任何客户端使用?
Connection conn = null;
CallableStatement cStmt = null;
try {
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put("java.naming.factory.initial", "org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory");
Context initContext = new InitialContext(environment);
DataSource ds = (DataSource) initContext.lookup("jdbc/tvaccount");
if (ds != null) {
conn = ds.getConnection();
cStmt = conn.prepareCall("{call getAccountStatusAttr(?)}");
cStmt.setString("pUserLogin", userName);
cStmt.execute();
}
} catch (Exception e) {
log.error("Exception while getting account status: ", e);
} finally {
if (cStmt != null) {
try {
cStmt.close();
} catch (SQLException e) {
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
答案 0 :(得分:0)
您是否已将此Java代码作为JAR文件添加到WSO2 ESB中,然后使用类介体访问该方法?如果是这种情况,那么它的行为就像普通的java代码,其中一旦执行查询,连接将被关闭。