我在Tomcat的server.xml中配置了數據源
調用程式如下:
public class SqlBeanPool{
public Connection conn=null;
public Statement stmt=null;
public Statement stmt2=null;
public SqlBeanPool(){}
public void createConnection(){
try{
Context ctx = new InitialContext();
DataSource ds =(DataSource)ctx.lookup( "java:comp/env/jdbc/OracleDB ");
conn= ds.getConnection();
stmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
stmt2=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
}catch(Exception e){
System.out.print( "connect error: "+e.toString()+ " <br> ");
}
}//end funtion creatConnection();
public void freeConnection(){
if(stmt!=null){try{stmt.close();}catch (SQLException e){}stmt=null;}
if(stmt2!=null){try{stmt2.close();}catch (SQLException e){}stmt2=null;}
if(conn!=null){try{conn.close();}catch(SQLException e){}conn=null;}
}//end funtion;
}
在執行查詢時,報錯如下,也就是在關閉stmt的那一行:
java.lang.NullPointerException
oracle.jdbc.driver.ScrollableResultSet.close(ScrollableResultSet.java)
org.apache.commons.dbcp.DelegatingResultSet.close(DelegatingResultSet.java:193)
org.apache.jsp.control.invoice_005fdetail_jsp._jspService(invoice_005fdetail_jsp.java:463)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
請問怎樣解決?
------解决方案--------------------
好像是没有取到数据源,检查jndi名字,server.xml中数据源的设置
------解决方案--------------------
超过了连接池最大连接数?-_-!
一方面设大一些,另外检查一下为什么不够用,是不是有忘记释放的地方。