日志报错:set.java.sql.SQLException: Illegal operation on empty result set.org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object不能连接到数据源
怀疑有连接没有关闭.请帮忙看看代码.谢谢
DBConnSource.java:
*
* 数据源连接BEAN
*/
package mybean;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class DBConnSource {
private Connection conn;
private Statement stmt;
private PreparedStatement pstmt;
public DBConnSource(String dsName){
try{
Context initCtx = new InitialContext();
Context ctx =(Context)initCtx.lookup("java:comp/env");
DataSource ds =(DataSource)ctx.lookup(dsName);
conn = ds.getConnection();
}
catch(Exception e)
{
System.out.print(e.toString());
}
}
public synchronized Statement getStmt()throws Exception
{
stmt=conn.createStatement();
return stmt;
}
public synchronized PreparedStatement getPstmt(String sql)throws Exception
{
pstmt=conn.prepareStatement(sql);
return pstmt;
}
public void DBclose(){
try{ //关闭 Connection conn;
if(conn!=null){
conn.close();
}
}catch(Exception e){
System.out.print(e.toString());
}finally{
conn=null;
}
try{ //关闭Statement stmt;
if(stmt!=null){
stmt.close();
}
}catch(Exception e){
System.out.print(e.toString());