【发布时间】:2015-10-10 21:32:27
【问题描述】:
我尝试连接到 Oracle 数据库(检查连接状态)。我正在使用以下代码,效果很好。
public String getDatabaseStatus() {
Connection conn;
try {
conn = DriverManager.getConnection( "jdbc:oracle:thin:@192.168.0.70:1521:XE", "foo","bar");
conn.close();
} catch (Exception e) {
return "ERR - " + e.getMessage();
}
return "Connection succesful";
}
但是,当使用 Websphere 数据源时,在 10 次(连接限制)刷新后页面会挂起。代码:
public String getDatabaseStatus() {
Connection conn;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/xe");
conn = WSCallHelper.getNativeConnection(ds.getConnection());
} catch (Exception e) {
return "ERR - " + e.getMessage();
}
return "Connection succesful";
}
我试图关闭提供的连接,但它给了我错误:
J2CA0206W - 发生连接错误。为了帮助确定问题,请在连接工厂或数据源上启用诊断连接使用选项。这是多线程访问检测选项。或者检查 Database 或 MessageProvider 是否可用。
任何帮助将不胜感激。
【问题讨论】:
-
WSCallHelper.getNativeConnection(...)是做什么的? -
我可以通过这种方式获得本地 Oracle 连接。我需要这个来从 Oracle 函数中获取结果; OracleCallableStatement 是接收到的对象类型。
标签: oracle jakarta-ee jdbc websphere datasource