各位急救!为什么我已经关闭conn连接了,还是会出现这样的错误?
Cannot get a connection, pool exhausted
拜托各位解救下~~万分感激了
------解决方案--------------------ry {
数据库操作代码
} catch(Exception e) {
} finally {
if (rs != null) {
rs.close();
rs = null;
}
if (pst != null) {
pst.close();
pst = null;
}
if (db != null) {
db.freeConnection();
db = null;
}}
------解决方案--------------------ResultSet.close();
Statement.close();
Connection.close();
Connection=null;
if(Connection!=null)
Connection.close();
------解决方案--------------------Cannot make a static reference to the non-static method close() from the type ResultSet
不能建立静态方引用没有静态的CLOSE方法
给你看一段我写的代码
import java.sql.*;
import java.io.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
public class DBConecter
{
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
public DBConecter()
{
try
{
Context initCtx=new InitialContext();
DataSource ds=(DataSource)initCtx.lookup( "java:comp/env/jdbc/Filesample ");
conn=ds.getConnection();
//stmt=conn.createStatement();
//rs=stmt.executeQuery( "select * from authors; ");
}
catch(Exception e)
{
System.out.print( "出现例外,信息是: "+e.getMessage());
e.printStackTrace();
}
}
/**
*通过查询语句返回RESULTSET
*/
public ResultSet ExecQuery(String sql)
{
try
{
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e.toString());
}
return rs;
}
/**
*用于UPDATA、INSERT、DELETE等方法的执行方法 返回INT如执行正确返回值大于1
*/
public int ExecUpdate(String sql) {
int count = 0;
try
{
stmt = conn.createStatement();
count = stmt.executeUpdate(sql);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e.toString());
}
return count;
}
public void Commit() throws
SQLException {
conn.commit();
}
public void Rollback() throws SQLException
{
conn.rollback();
}
/*------关闭DB连接方法-------*/
public void closeconn()
{
try
{
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}