Adwait Chitaley
asked on
Connection pooling
hi sorry to trouble u again.....i`m facing some problem in connection pooling
dsource.getConnection() returns null, ..behavior is inconsistence some time i get connection object some time null can u pls help me regarding asap
java.lang.NullPointerExcep tion
datasource connection return nulll
<data-sources>
<data-source type="oracle.jdbc.pool.Ora cleDataSou rce">
<set-property property="autoCommit" value="false"/>
<set-property property="description" value="Configuration"/>
<set-property property="driverClass" value="oracle.jdbc.OracleD river"/>
<set-property property="factory" value="org.apache.commons. dbcp.Basic DataSource Factory" />
<set-property property="URL" value="jdbc:oracle:thin:@1 28.127.50. 122:1521:a irsanchay" />
<set-property property="user" value="airuser"/>
<set-property property="password" value="airsample"/>
<set-property property="maxCount" value="20"/>
<set-property property="minCount" value="2"/>
</data-source>
</data-sources>
ServletContext application=servlet.getSer vletContex t();
DataSource datasource = (DataSource) application.getAttribute(G lobals.DAT A_SOURCE_K EY);
ConnectionPool.dsource=dat asource;
return mapping.findForward(SUCCES S);
public static Connection openConnection() throws Exception{
Connection con = null;
con = dsource.getConnection();
message = "Successful Connection.";
System.out.println("-----c onOpenedCo unt---->>" +(++conOpe nedCount)) ;
return con;
dsource.getConnection() returns null, ..behavior is inconsistence some time i get connection object some time null can u pls help me regarding asap
java.lang.NullPointerExcep
datasource connection return nulll
<data-sources>
<data-source type="oracle.jdbc.pool.Ora
<set-property property="autoCommit" value="false"/>
<set-property property="description" value="Configuration"/>
<set-property property="driverClass" value="oracle.jdbc.OracleD
<set-property property="factory" value="org.apache.commons.
<set-property property="URL" value="jdbc:oracle:thin:@1
<set-property property="user" value="airuser"/>
<set-property property="password" value="airsample"/>
<set-property property="maxCount" value="20"/>
<set-property property="minCount" value="2"/>
</data-source>
</data-sources>
ServletContext application=servlet.getSer
DataSource datasource = (DataSource) application.getAttribute(G
ConnectionPool.dsource=dat
return mapping.findForward(SUCCES
public static Connection openConnection() throws Exception{
Connection con = null;
con = dsource.getConnection();
message = "Successful Connection.";
System.out.println("-----c
return con;
ASKER
no not running out of connection and all connection close properly....
could it be b`coz of connection pooling configuration.. in struts-config.xml ...???
could it be b`coz of connection pooling configuration.. in struts-config.xml ...???
how do you know you aren't running out of connections?
ASKER
i encounter out of connection exception once ..and its b`coz connection not closed properly..
but this time around i`m closing all connection i used...so i guess its not running out of connection...
this is my ConnectionPool.java file where i open,close and execute query
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.airsanchay.util;
import java.sql.CallableStatement ;
import javax.sql.DataSource;
import java.util.HashMap;
import java.sql.Connection;
import java.sql.PreparedStatement ;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author santoshi
*/
public class ConnectionPool {
public static String message = "Not Connected";
public static DataSource dsource = null;
public static int conOpenedCount=0;
public static int conClosedCount=0;
public static final HashMap CONNECTIONS=new HashMap();
public ConnectionPool(DataSource dsource){
ConnectionPool.dsource = dsource;
}
public static Connection openConnection() throws Exception{
Connection con = null;
con = dsource.getConnection();
message = "Successful Connection.";
System.out.println("-----c onOpenedCo unt---->>" +(++conOpe nedCount)) ;
return con;
}
public static void closeConnection(Connection con,ResultSet rs){
if(con==null){
return;
}
try {
rs.close();
con.close();
System.out.println("----co nnection closed---->>"+(++conClosed Count));
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static ResultSet executeQuery(String sqlQuery){
if(sqlQuery ==null ){
return null;
}
ResultSet rs=null;
PreparedStatement stmt=null;
Connection con=null;
try{
con=ConnectionPool.openCon nection();
stmt = con.prepareStatement(sqlQu ery);
rs = stmt.executeQuery();
return rs;
}catch(Exception e ){
e.printStackTrace();
ConnectionPool.closePrepar edStatemen t(stmt);
ConnectionPool.closeResult Set(rs);
ConnectionPool.closeConnec tion(con);
return rs;
}finally{
if(rs!=null){
ConnectionPool.CONNECTIONS .put(rs.to String(), con);
}
}
}
public static void closeConnection(Connection con){
if(con==null){
return;
}
try {
con.close();
System.out.println("----co nnection closed---->>"+(++conClosed Count));
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/** close resultSet and connection *****/
public static void closeResultSet(ResultSet rs){
if(rs==null){
return;
}
try {
rs.close();
Connection con= (Connection) ConnectionPool.CONNECTIONS .get(rs.to String());
ConnectionPool.CONNECTIONS .remove(rs .toString( ));
//System.out.println("---- connection closed---->>"+(++conClosed Count));
ConnectionPool.closeConnec tion(con);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void closePreparedStatement(Pre paredState ment stmt){
if(stmt==null){
return;
}
try {
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void closeCollableStatement(Cal lableState ment stmt){
if(stmt==null){
return;
}
try {
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
this my login action class
package com.airsanchay.action;
import com.airsanchay.bean.LoginA ctionForm;
import com.airsanchay.model.Login Model;
import com.airsanchay.util.AuditL og;
import java.net.InetAddress;
import javax.servlet.ServletConte xt;
import javax.servlet.http.HttpSer vletReques t;
import javax.servlet.http.HttpSer vletRespon se;
import javax.servlet.http.HttpSes sion;
import org.apache.struts.action.A ction;
import org.apache.struts.action.A ctionForm;
import org.apache.struts.action.A ctionMappi ng;
import org.apache.struts.action.A ctionForwa rd;
/**
*
* @author santoshi
*/
public class LoginAction extends Action {
private final static int LOGIN_SUCCESSFUL=1;
private final static int LOGIN_FAIL=2;
private final static String VALID= "valid";
private final static String INVALID = "invalid";
private ServletContext application=null;
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginActionForm loginForm= (LoginActionForm) form;
HttpSession ssn = request.getSession();
//check ServletContext application created in SessionListener
if(application==null){
//initialize with ServletContex
this.application=this.getS ervlet().g etServletC ontext();
}
int check = new LoginModel().authorizeUser (loginForm .getUserna me(), loginForm.getPassword(),re quest,appl ication);
System.out.println("Login Returned: "+check);
String userid = "";
int userId = 0;
if(check==LOGIN_SUCCESSFUL ){
userid = ssn.getAttribute("UserId") .toString( );
userId = Integer.parseInt(userid);
System.out.println("User id: "+userId);
new AuditLog().updateSystemAcc essLog(Ine tAddress.g etLocalHos t().getHos tAddress() ,"Session Created","Successful Login",userId);
new AuditLog().updateAuditSess ion(userId , ssn.getId());
return mapping.findForward(VALID) ;
} else if(check==LOGIN_FAIL){
if(userid==null){
userId=0;
}
System.out.println("User id: "+userId);
System.out.println("IP address: "+InetAddress.getLocalHost ().getHost Address()) ;
new AuditLog().updateSystemAcc essLog(Ine tAddress.g etLocalHos t().getHos tAddress() ,"Session Creation Failed","Error In Login",userId);
}
return mapping.findForward(INVALI D);
}
}
this my loginmodel class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.airsanchay.model;
import com.airsanchay.util.Connec tionPool;
import java.sql.ResultSet;
import java.util.HashMap;
import javax.servlet.ServletConte xt;
import javax.servlet.http.HttpSer vletReques t;
import javax.servlet.http.HttpSes sion;
/**
*
* @author santoshi
*/
public class LoginModel {
HashMap LOGIN_USERS;
private final static int LOGIN_SUCCESSFUL=1;
private final static int LOGIN_FAIL=2;
private final static int USER_ALREADY_LOGGED_IN=3;
private ResultSet rs = null;
/**
*
* @param username
* @param password
* @param req
* @param application
* @return
* @throws java.lang.Exception
* authorized user login, check user existing status,username, password
* check user USER_ALREADY_LOGGED_IN
*/
public int authorizeUser(String username,String password,HttpServletReques t req, ServletContext application) throws Exception {
int userId=0;
String userFullName=null;
HttpSession ses = req.getSession();
try {
String query = " SELECT user_id,user_full_name,use r_login,Pk g_Pass_Enp _Dep.decry pt(USER_PA SSWORD) " +
" FROM M55_USERS WHERE user_login = '"+username+"'" +
" and Pkg_Pass_Enp_Dep.decrypt(U SER_PASSWO RD) =" +
" '"+password+"' and USER_ACTIVE_STATUS= '1' ";
/********* this is where i execute quesry**********/
rs = ConnectionPool.executeQuer y(query);
System.out.println("Login query..."+query);
if(rs.next()){
userId=rs.getInt("user_id" );
userFullName=rs.getString( "user_full _name");
}
if(userId!=0){
// initialized LOGIN_USERS from application context set in ApplicattionListener
LOGIN_USERS=(HashMap)appli cation.get Attribute( "aLoginUse rs");
if(LOGIN_USERS.get(Integer .toString( userId)) == null){
ses.setAttribute("UserId", Integer.toString(userId));
ses.setAttribute("fullname ", userFullName);
LOGIN_USERS.put(Integer.to String(use rId), ses);
application.setAttribute(" aLoginUser s", LOGIN_USERS);
ses.removeAttribute("login fail");
return LOGIN_SUCCESSFUL;
}else{
ses.setAttribute("UserId", Integer.toString(userId));
return USER_ALREADY_LOGGED_IN;
}
}
} catch (Exception e){
e.printStackTrace();
} finally {
/****this is where i close result set and Connection ****//
ConnectionPool.closeResult Set(rs);
}
ses.setAttribute("loginfai l","Login Fail Please Try Again...");
return LOGIN_FAIL;
}
}
but this time around i`m closing all connection i used...so i guess its not running out of connection...
this is my ConnectionPool.java file where i open,close and execute query
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.airsanchay.util;
import java.sql.CallableStatement
import javax.sql.DataSource;
import java.util.HashMap;
import java.sql.Connection;
import java.sql.PreparedStatement
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author santoshi
*/
public class ConnectionPool {
public static String message = "Not Connected";
public static DataSource dsource = null;
public static int conOpenedCount=0;
public static int conClosedCount=0;
public static final HashMap CONNECTIONS=new HashMap();
public ConnectionPool(DataSource dsource){
ConnectionPool.dsource = dsource;
}
public static Connection openConnection() throws Exception{
Connection con = null;
con = dsource.getConnection();
message = "Successful Connection.";
System.out.println("-----c
return con;
}
public static void closeConnection(Connection
if(con==null){
return;
}
try {
rs.close();
con.close();
System.out.println("----co
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static ResultSet executeQuery(String sqlQuery){
if(sqlQuery ==null ){
return null;
}
ResultSet rs=null;
PreparedStatement stmt=null;
Connection con=null;
try{
con=ConnectionPool.openCon
stmt = con.prepareStatement(sqlQu
rs = stmt.executeQuery();
return rs;
}catch(Exception e ){
e.printStackTrace();
ConnectionPool.closePrepar
ConnectionPool.closeResult
ConnectionPool.closeConnec
return rs;
}finally{
if(rs!=null){
ConnectionPool.CONNECTIONS
}
}
}
public static void closeConnection(Connection
if(con==null){
return;
}
try {
con.close();
System.out.println("----co
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/** close resultSet and connection *****/
public static void closeResultSet(ResultSet rs){
if(rs==null){
return;
}
try {
rs.close();
Connection con= (Connection) ConnectionPool.CONNECTIONS
ConnectionPool.CONNECTIONS
//System.out.println("----
ConnectionPool.closeConnec
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void closePreparedStatement(Pre
if(stmt==null){
return;
}
try {
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void closeCollableStatement(Cal
if(stmt==null){
return;
}
try {
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
this my login action class
package com.airsanchay.action;
import com.airsanchay.bean.LoginA
import com.airsanchay.model.Login
import com.airsanchay.util.AuditL
import java.net.InetAddress;
import javax.servlet.ServletConte
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSes
import org.apache.struts.action.A
import org.apache.struts.action.A
import org.apache.struts.action.A
import org.apache.struts.action.A
/**
*
* @author santoshi
*/
public class LoginAction extends Action {
private final static int LOGIN_SUCCESSFUL=1;
private final static int LOGIN_FAIL=2;
private final static String VALID= "valid";
private final static String INVALID = "invalid";
private ServletContext application=null;
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginActionForm loginForm= (LoginActionForm) form;
HttpSession ssn = request.getSession();
//check ServletContext application created in SessionListener
if(application==null){
//initialize with ServletContex
this.application=this.getS
}
int check = new LoginModel().authorizeUser
System.out.println("Login Returned: "+check);
String userid = "";
int userId = 0;
if(check==LOGIN_SUCCESSFUL
userid = ssn.getAttribute("UserId")
userId = Integer.parseInt(userid);
System.out.println("User id: "+userId);
new AuditLog().updateSystemAcc
new AuditLog().updateAuditSess
return mapping.findForward(VALID)
} else if(check==LOGIN_FAIL){
if(userid==null){
userId=0;
}
System.out.println("User id: "+userId);
System.out.println("IP address: "+InetAddress.getLocalHost
new AuditLog().updateSystemAcc
}
return mapping.findForward(INVALI
}
}
this my loginmodel class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.airsanchay.model;
import com.airsanchay.util.Connec
import java.sql.ResultSet;
import java.util.HashMap;
import javax.servlet.ServletConte
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSes
/**
*
* @author santoshi
*/
public class LoginModel {
HashMap LOGIN_USERS;
private final static int LOGIN_SUCCESSFUL=1;
private final static int LOGIN_FAIL=2;
private final static int USER_ALREADY_LOGGED_IN=3;
private ResultSet rs = null;
/**
*
* @param username
* @param password
* @param req
* @param application
* @return
* @throws java.lang.Exception
* authorized user login, check user existing status,username, password
* check user USER_ALREADY_LOGGED_IN
*/
public int authorizeUser(String username,String password,HttpServletReques
int userId=0;
String userFullName=null;
HttpSession ses = req.getSession();
try {
String query = " SELECT user_id,user_full_name,use
" FROM M55_USERS WHERE user_login = '"+username+"'" +
" and Pkg_Pass_Enp_Dep.decrypt(U
" '"+password+"' and USER_ACTIVE_STATUS= '1' ";
/********* this is where i execute quesry**********/
rs = ConnectionPool.executeQuer
System.out.println("Login query..."+query);
if(rs.next()){
userId=rs.getInt("user_id"
userFullName=rs.getString(
}
if(userId!=0){
// initialized LOGIN_USERS from application context set in ApplicattionListener
LOGIN_USERS=(HashMap)appli
if(LOGIN_USERS.get(Integer
ses.setAttribute("UserId",
ses.setAttribute("fullname
LOGIN_USERS.put(Integer.to
application.setAttribute("
ses.removeAttribute("login
return LOGIN_SUCCESSFUL;
}else{
ses.setAttribute("UserId",
return USER_ALREADY_LOGGED_IN;
}
}
} catch (Exception e){
e.printStackTrace();
} finally {
/****this is where i close result set and Connection ****//
ConnectionPool.closeResult
}
ses.setAttribute("loginfai
return LOGIN_FAIL;
}
}
ASKER
this exception i get when i try to login
java.lang.NullPointerExcep tion
at com.airsanchay.util.Connec tionPool.o penConnect ion(Connec tionPool.j ava:34)
at com.airsanchay.util.Connec tionPool.e xecuteQuer y(Connecti onPool.jav a:62)
at com.airsanchay.model.Login Model.auth orizeUser( LoginModel .java:52)
at com.airsanchay.action.Logi nAction.ex ecute(Logi nAction.ja va:60)
at org.apache.struts.action.R equestProc essor.proc essActionP erform(Req uestProces sor.java:4 31)
at org.apache.struts.action.R equestProc essor.proc ess(Reques tProcessor .java:236)
at org.apache.struts.action.A ctionServl et.process (ActionSer vlet.java: 1196)
at org.apache.struts.action.A ctionServl et.doPost( ActionServ let.java:4 32)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 710)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 803)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:290 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06)
at org.netbeans.modules.web.m onitor.ser ver.Monito rFilter.do Filter(Mon itorFilter .java:390)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:235 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:233)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:175)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:128 )
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:102 )
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :109)
at org.apache.catalina.connec tor.Coyote Adapter.se rvice(Coyo teAdapter. java:263)
at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:844)
at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocess(Http 11Protocol .java:584)
at org.apache.tomcat.util.net .JIoEndpoi nt$Worker. run(JIoEnd point.java :447)
at java.lang.Thread.run(Threa d.java:595 )
java.lang.NullPointerExcep
at com.airsanchay.util.Connec
at com.airsanchay.util.Connec
at com.airsanchay.model.Login
at com.airsanchay.action.Logi
at org.apache.struts.action.R
at org.apache.struts.action.R
at org.apache.struts.action.A
at org.apache.struts.action.A
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.netbeans.modules.web.m
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.connec
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
at java.lang.Thread.run(Threa
That ConnectionPool class does not seem necessary, and not sure how reliable it is
you haven't said why you don't think you are running out of connections?
you haven't said why you don't think you are running out of connections?
> con = dsource.getConnection();
that exception suggests you are not even getting a datasource
Is the above line 34?
that exception suggests you are not even getting a datasource
Is the above line 34?
ASKER
but when i restart netbean IDE i get connection
you're probably incorrectly creating a ConnectionPool instance, that class does not serve any purpose that I can see. You shouldn't be trying to store connections thats what the connection pool is for.
ASKER
for my convenience , i created the ConnectionPool class to track count of open and close connection,
also i dont want to declare Connection in my action or model class every time when i execute query..for that i declare executeQuery(string str) which manage open connection and i stored it in CONNECTION hash map with rs.toString() key
public static ResultSet executeQuery(String sqlQuery){
if(sqlQuery ==null ){
return null;
}
ResultSet rs=null;
PreparedStatement stmt=null;
Connection con=null;
try{
con=ConnectionPool.openCon nection();
stmt = con.prepareStatement(sqlQu ery);
rs = stmt.executeQuery();
return rs;
}catch(Exception e ){
e.printStackTrace();
ConnectionPool.closePrepar edStatemen t(stmt);
ConnectionPool.closeResult Set(rs);
ConnectionPool.closeConnec tion(con);
return rs;
}finally{
if(rs!=null){
ConnectionPool.CONNECTIONS .put(rs.to String(), con);
}
}
when i close connection using closeResultSet(ResultSet rs) , i use rs.toString() key to get appropriate connection from HashMap to close and also remove connection from hash map CONNECTION
public static void closeResultSet(ResultSet rs){
if(rs==null){
return;
}
try {
rs.close();
Connection con= (Connection) ConnectionPool.CONNECTIONS .get(rs.to String());
ConnectionPool.CONNECTIONS .remove(rs .toString( ));
//System.out.println("---- connection closed---->>"+(++conClosed Count));
ConnectionPool.closeConnec tion(con);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
also i dont want to declare Connection in my action or model class every time when i execute query..for that i declare executeQuery(string str) which manage open connection and i stored it in CONNECTION hash map with rs.toString() key
public static ResultSet executeQuery(String sqlQuery){
if(sqlQuery ==null ){
return null;
}
ResultSet rs=null;
PreparedStatement stmt=null;
Connection con=null;
try{
con=ConnectionPool.openCon
stmt = con.prepareStatement(sqlQu
rs = stmt.executeQuery();
return rs;
}catch(Exception e ){
e.printStackTrace();
ConnectionPool.closePrepar
ConnectionPool.closeResult
ConnectionPool.closeConnec
return rs;
}finally{
if(rs!=null){
ConnectionPool.CONNECTIONS
}
}
when i close connection using closeResultSet(ResultSet rs) , i use rs.toString() key to get appropriate connection from HashMap to close and also remove connection from hash map CONNECTION
public static void closeResultSet(ResultSet rs){
if(rs==null){
return;
}
try {
rs.close();
Connection con= (Connection) ConnectionPool.CONNECTIONS
ConnectionPool.CONNECTIONS
//System.out.println("----
ConnectionPool.closeConnec
} catch (SQLException ex) {
ex.printStackTrace();
}
}
>>for my convenience , i created the ConnectionPool class to track count of open and close connection,
You'd be better off doing that via logging in the connection pool rather than adding complexity that seems largely redundant
You'd be better off doing that via logging in the connection pool rather than adding complexity that seems largely redundant
> for my convenience , i created the ConnectionPool class to track count of open and close connection,
thers no need, its already looked after for you.
And the numbers won't be correct anyway because the pool controls when the actual connection gets closed.
> when i close connection using closeResultSet(ResultSet rs) , i use rs.toString() key to get appropriate connection from HashMap to close and also remove connection from hash map CONNECTION
that approach won't work. Instead just close the connection directly after you have finished with it.
thers no need, its already looked after for you.
And the numbers won't be correct anyway because the pool controls when the actual connection gets closed.
> when i close connection using closeResultSet(ResultSet rs) , i use rs.toString() key to get appropriate connection from HashMap to close and also remove connection from hash map CONNECTION
that approach won't work. Instead just close the connection directly after you have finished with it.
ASKER
can u please give me example for that
Connection con = dataSource.getConnection() ;
try {
// do your sql
} catch (Exception ex) {
ex.printStackTrace();
} finally {
con.close();
}
keep it simple :)
commons dbutil has classes to simplify things for you
try {
// do your sql
} catch (Exception ex) {
ex.printStackTrace();
} finally {
con.close();
}
keep it simple :)
commons dbutil has classes to simplify things for you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
make sure you are closing the connections once you are done with them