我在多米诺骨牌服务器上创建了一个servlet,我第一次调用它时看到没有错误,但在看到之后:
java.sql.SQLException:连接不存在。 在com.ibm.as400.access.JDError.throwSQLException(JDError.java:389) 在com.ibm.as400.access.AS400JDBCConnection.checkOpen(AS400JDBCConnection.java:394) 在com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1868) 在com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1703)
如果我想调用servlet,我每次都必须重启多米诺服务器 我试图不关闭代码中的连接并且它工作但这个解决方案可能会导致性能问题
任何其他解决方案将不胜感激
编辑:
使用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();
}
}}
提前致谢。