我在domino服务器中创建了一个servlet,第一次调用它时没有看到任何错误,但在看到它之后:
java.sql.SQLException:连接不存在。网址:com.ibm.as400.access.JDError.sthrowSQLException(JDError.java:389)网址:com.ibm.as400.access.AS400JDBConnection.checkOpen(AS400JDBConnection.java:394)网址:com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1868)网址:com.ibm.as400.access.AS400JDBConnection.prepareStatement(AS400JDBConnection.java:1703)
如果我想调用servlet,现在每次domino服务器时都必须重新启动我试着不关闭代码中的连接,它起了作用,但这个解决方案可能会导致性能问题
任何其他解决方案都将受到赞赏
编辑:
在使用Apache DBCP之后,我有另一个错误:
java.sql.SQLException:连接已关闭。网址:org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(P??oolingDataSource.java:175)网址:org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStat??ement(PoolingDataSource.java:301)
COODE获取/汇集连接:
公共类ConnexionAS400{
public static ConnexionAS400 connexionAS4000= null;
private static Connection connAS400 = null;
public static ConnexionAS400 getInstance(){
if(connexionAS4000 == null)
connexionAS4000 = new ConnexionAS400();
return connexionAS4000;
}
private ConnexionAS400(){
String Url = "jdbc:as400://172.31.5.100";
String Username = "DEVATIRD";
String Password = "ATIRD";
String Driver = "com.ibm.as400.access.AS400JDBCDriver";
try
{
Class.forName(Driver);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(Url,Username,Password);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, new GenericObjectPool(null), null, "SELECT 1", false, true);
ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory,GenericObjectPool.DEFAULT_MAX_ACTIVE,GenericObjectPool.WHEN_EXHAUSTED_GROW,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,false,true);
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
connAS400 = dataSource.getConnection();
}
catch (NoClassDefFoundError exno)
{
System.out.println("ERREUR: Impossible de charger la classe");
exno.printStackTrace();
}
catch (Exception e)
{
System.out.println("ERREUR: Impossible de charger le driver JDBC AS400.");
e.printStackTrace();
}
}
public Connection openConnectionAS400() {
return connAS400;
}
public void closeConnectionAS400() {
try {
connAS400.close();
} catch (SQLException e) {
System.out
.println("ERREUR: Lors de la fermeture de la connection.");
e.printStackTrace();
}
}}
提前谢谢。
这可能是一个线程问题。您应该使用连接池来管理JDBC连接,例如Apache DBCP、C3P0,或者您的容器提供的机制(如果有的话)。