OracleConnectionPoolDataSource creates too many connections
Hi All, My web application is using up all connections after running for a while. It's quite obvious that I'm not using the connection pool as it was designed to be used. The only way I can get these connections back is by restarting the Tomcat. I have ojdbc14.jar in the following directories: $CATALINA_HOME/commons/lib directory $CATALINA_HOME/webapps/myWebApp/WEB-INF/lib. This code creates my connection Pool private void createConnectionPool( ) { try { // Create a OracleConnectionPoolDataSource instance. connectionPoolDS = new OracleConnectionPoolDataSource( ); String url = jdbc:oracle:thin:@194.26.151.17:1521:mosaic; connectionPoolDS.setURL( url ); // Set the user name. connectionPoolDS.setUser(mosaicuser); // Set the password. connectionPoolDS.setPassword(mosa1c); } catch ( SQLException ex ) { // Catch SQL errors. //context.log( ex.toString( ) ); // log errors. } } This code creates a PooledConnection. - public static synchronized PooledConnection getPooledConnection(){ try{ pooledconn = connectionPoolDS.getPooledConnection(); }catch(SQLException sqle){ sqle.printStackTrace(); } return pooledconn; } In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); On an JSP Page: ServletContext ctx = getServletContext(); PooledConnection pc = (PooledConnection)ctx.getAttribute(pooled_conn); Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } Any help to solve this mystery would be very much appreciated. Kind Regards, Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OracleConnectionPoolDataSource creates too many connections
Hi, You still need to create a connection cache with that datasource, so something like : OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource(); ... OracleConnectionCache oracleConnectionCache = new OracleConnectionCacheImpl(ocpds); You can then call the following to get connections from the pool : oracleConnectionCache.getConnection(); Be sure to close all your connection when you are done so they are returned to the pool. Ryan. -Original Message- From: Rudi Doku [mailto:[EMAIL PROTECTED] Sent: 03 March 2004 09:04 To: Tomcat Users List Subject: OracleConnectionPoolDataSource creates too many connections Importance: High Hi All, My web application is using up all connections after running for a while. It's quite obvious that I'm not using the connection pool as it was designed to be used. The only way I can get these connections back is by restarting the Tomcat. I have ojdbc14.jar in the following directories: $CATALINA_HOME/commons/lib directory $CATALINA_HOME/webapps/myWebApp/WEB-INF/lib. This code creates my connection Pool private void createConnectionPool( ) { try { // Create a OracleConnectionPoolDataSource instance. connectionPoolDS = new OracleConnectionPoolDataSource( ); String url = jdbc:oracle:thin:@194.26.151.17:1521:mosaic; connectionPoolDS.setURL( url ); // Set the user name. connectionPoolDS.setUser(mosaicuser); // Set the password. connectionPoolDS.setPassword(mosa1c); } catch ( SQLException ex ) { // Catch SQL errors. //context.log( ex.toString( ) ); // log errors. } } This code creates a PooledConnection. - public static synchronized PooledConnection getPooledConnection(){ try{ pooledconn = connectionPoolDS.getPooledConnection(); }catch(SQLException sqle){ sqle.printStackTrace(); } return pooledconn; } In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); On an JSP Page: ServletContext ctx = getServletContext(); PooledConnection pc = (PooledConnection)ctx.getAttribute(pooled_conn); Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } Any help to solve this mystery would be very much appreciated. Kind Regards, Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OracleConnectionPoolDataSource creates too many connections
Probably you are not closing all the objects. It depends on pool used and app server but is a good idea (and more portable) to close all the objects. Many pools crash if you only close (return) the connections. after using the rs object (ResultSet) -- rs.close() after using the st object (Statement) -- st.close() after using the pst object (PreparedStatement) -- pst.close() after using ... (all the jdbc objects) You must close, to avoid errors, in reverse order as they were instantiated. Try it, i have no read your code and could be other problems. Hope this help Marcos -Mensaje original- De: Rudi Doku [mailto:[EMAIL PROTECTED] Enviado el: miércoles, 03 de marzo de 2004 10:04 Para: Tomcat Users List Asunto: OracleConnectionPoolDataSource creates too many connections Importancia: Alta Hi All, My web application is using up all connections after running for a while. It's quite obvious that I'm not using the connection pool as it was designed to be used. The only way I can get these connections back is by restarting the Tomcat. I have ojdbc14.jar in the following directories: $CATALINA_HOME/commons/lib directory $CATALINA_HOME/webapps/myWebApp/WEB-INF/lib. This code creates my connection Pool private void createConnectionPool( ) { try { // Create a OracleConnectionPoolDataSource instance. connectionPoolDS = new OracleConnectionPoolDataSource( ); String url = jdbc:oracle:thin:@194.26.151.17:1521:mosaic; connectionPoolDS.setURL( url ); // Set the user name. connectionPoolDS.setUser(mosaicuser); // Set the password. connectionPoolDS.setPassword(mosa1c); } catch ( SQLException ex ) { // Catch SQL errors. //context.log( ex.toString( ) ); // log errors. } } This code creates a PooledConnection. - public static synchronized PooledConnection getPooledConnection(){ try{ pooledconn = connectionPoolDS.getPooledConnection(); }catch(SQLException sqle){ sqle.printStackTrace(); } return pooledconn; } In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); On an JSP Page: ServletContext ctx = getServletContext(); PooledConnection pc = (PooledConnection)ctx.getAttribute(pooled_conn); Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } Any help to solve this mystery would be very much appreciated. Kind Regards, Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] **AVISO LEGAL** Este mensaje es privado y confidencial y solamente para la persona a la que va dirigido. Si usted ha recibido este mensaje por error, no debe revelar, copiar, distribuir o usarlo en ningún sentido. Le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. No hay renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión errónea o mal funcionamiento. Cualquier opinión expresada en este mensaje pertenece únicamente al autor remitente, y no representa necesariamente la opinión de Santander Central Hispano, a no ser que expresamente se diga y el remitente esté autorizado para hacerlo. Los correos electrónicos no son seguros, no garantizan la confidencialidad ni la correcta recepción de los mismos, dado que pueden ser interceptados, manipulados, destruidos, llegar con demora, incompletos, o con virus. Santander Central Hispano no se hace responsable de las alteraciones que pudieran hacerse al mensaje una vez enviado. Este mensaje sólo tiene una finalidad de información, y no debe interpretarse como una oferta de venta o de compra de valores ni de instrumentos financieros relacionados. En el caso de que el destinatario de este mensaje no consintiera la utilización del correo electrónico via Internet, rogamos lo ponga en nuestro conocimiento. **DISCLAIMER** This message is private and confidential and it is intended exclusively for the addressee. If you receive this message by mistake, you should not disseminate, distribute or copy this e-mail. Please inform the sender and delete the message and attachments from your system. No confidentiality nor any privilege regarding the information is waived or lost by any mistransmission or malfunction. Any views or opinions contained in this message are solely those of the author, and do not necessarily represent those
Re: RE: OracleConnectionPoolDataSource creates too many connections
Hi, I'm a newbie, and I need to learn more about connection pool. Can you suggest a tutorial or a web site where I can find more information? TIA Giuseppe Hi, You still need to create a connection cache with that datasource, so something like : OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource(); ... OracleConnectionCache oracleConnectionCache = new OracleConnectionCacheImpl(ocpds); You can then call the following to get connections from the pool : oracleConnectionCache.getConnection(); Be sure to close all your connection when you are done so they are returned to the pool. Ryan. -- Giuseppe Briotti [EMAIL PROTECTED] Alme Sol, curru nitido diem qui promis et celas aliusque et idem nasceris, possis nihil urbe Roma visere maius. (Orazio) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OracleConnectionPoolDataSource creates too many connections
Possible problems could be: - Connnections not getting closed - The max concurrent request for tomcat had been reached (check the number of connections in server.xml) - AC -Original Message- From: Rudi Doku [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 03, 2004 2:34 PM To: Tomcat Users List Subject: OracleConnectionPoolDataSource creates too many connections Importance: High Hi All, My web application is using up all connections after running for a while. It's quite obvious that I'm not using the connection pool as it was designed to be used. The only way I can get these connections back is by restarting the Tomcat. I have ojdbc14.jar in the following directories: $CATALINA_HOME/commons/lib directory $CATALINA_HOME/webapps/myWebApp/WEB-INF/lib. This code creates my connection Pool private void createConnectionPool( ) { try { // Create a OracleConnectionPoolDataSource instance. connectionPoolDS = new OracleConnectionPoolDataSource( ); String url = jdbc:oracle:thin:@194.26.151.17:1521:mosaic; connectionPoolDS.setURL( url ); // Set the user name. connectionPoolDS.setUser(mosaicuser); // Set the password. connectionPoolDS.setPassword(mosa1c); } catch ( SQLException ex ) { // Catch SQL errors. //context.log( ex.toString( ) ); // log errors. } } This code creates a PooledConnection. - public static synchronized PooledConnection getPooledConnection(){ try{ pooledconn = connectionPoolDS.getPooledConnection(); }catch(SQLException sqle){ sqle.printStackTrace(); } return pooledconn; } In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); On an JSP Page: ServletContext ctx = getServletContext(); PooledConnection pc = (PooledConnection)ctx.getAttribute(pooled_conn); Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } Any help to solve this mystery would be very much appreciated. Kind Regards, Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RE: OracleConnectionPoolDataSource creates too many connections
You need to use the .close method for every connection. If your new connection is called conn then it's conn.close(); Check your max connections in server.xml (probably for port 8009) but if you're not closing your connections this will only delay a crash not stop it. I suggest the java.sun.com site for info on Java classes and methods. You could use this link: http://java.sun.com/j2se/1.3/docs/api/ Adam. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OracleConnectionPoolDataSource creates too many connections
Really, I have looked in web.xml and I can't seem to locate anything that is related to database connections. The only settings related to connections that I can see are related to JDBC realms. -Original Message- From: Arnab Chakravarty [mailto:[EMAIL PROTECTED] Sent: 03 March, 2004 11:53 AM To: Tomcat Users List Subject: RE: OracleConnectionPoolDataSource creates too many connections Possible problems could be: - Connnections not getting closed - The max concurrent request for tomcat had been reached (check the number of connections in server.xml) - AC -Original Message- From: Rudi Doku [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 03, 2004 2:34 PM To: Tomcat Users List Subject: OracleConnectionPoolDataSource creates too many connections Importance: High Hi All, My web application is using up all connections after running for a while. It's quite obvious that I'm not using the connection pool as it was designed to be used. The only way I can get these connections back is by restarting the Tomcat. I have ojdbc14.jar in the following directories: $CATALINA_HOME/commons/lib directory $CATALINA_HOME/webapps/myWebApp/WEB-INF/lib. This code creates my connection Pool private void createConnectionPool( ) { try { // Create a OracleConnectionPoolDataSource instance. connectionPoolDS = new OracleConnectionPoolDataSource( ); String url = jdbc:oracle:thin:@194.26.151.17:1521:mosaic; connectionPoolDS.setURL( url ); // Set the user name. connectionPoolDS.setUser(mosaicuser); // Set the password. connectionPoolDS.setPassword(mosa1c); } catch ( SQLException ex ) { // Catch SQL errors. //context.log( ex.toString( ) ); // log errors. } } This code creates a PooledConnection. - public static synchronized PooledConnection getPooledConnection(){ try{ pooledconn = connectionPoolDS.getPooledConnection(); }catch(SQLException sqle){ sqle.printStackTrace(); } return pooledconn; } In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); On an JSP Page: ServletContext ctx = getServletContext(); PooledConnection pc = (PooledConnection)ctx.getAttribute(pooled_conn); Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } Any help to solve this mystery would be very much appreciated. Kind Regards, Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OracleConnectionPoolDataSource creates too many connections
Hi Ryan, Thanks for the solution. I believe it's resolved my problem. Rudi -Original Message- From: Ryan Lissack [mailto:[EMAIL PROTECTED] Sent: 03 March, 2004 10:15 AM To: 'Tomcat Users List' Subject: RE: OracleConnectionPoolDataSource creates too many connections Hi, You still need to create a connection cache with that datasource, so something like : OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource(); ... OracleConnectionCache oracleConnectionCache = new OracleConnectionCacheImpl(ocpds); You can then call the following to get connections from the pool : oracleConnectionCache.getConnection(); Be sure to close all your connection when you are done so they are returned to the pool. Ryan. -Original Message- From: Rudi Doku [mailto:[EMAIL PROTECTED] Sent: 03 March 2004 09:04 To: Tomcat Users List Subject: OracleConnectionPoolDataSource creates too many connections Importance: High Hi All, My web application is using up all connections after running for a while. It's quite obvious that I'm not using the connection pool as it was designed to be used. The only way I can get these connections back is by restarting the Tomcat. I have ojdbc14.jar in the following directories: $CATALINA_HOME/commons/lib directory $CATALINA_HOME/webapps/myWebApp/WEB-INF/lib. This code creates my connection Pool private void createConnectionPool( ) { try { // Create a OracleConnectionPoolDataSource instance. connectionPoolDS = new OracleConnectionPoolDataSource( ); String url = jdbc:oracle:thin:@194.26.151.17:1521:mosaic; connectionPoolDS.setURL( url ); // Set the user name. connectionPoolDS.setUser(mosaicuser); // Set the password. connectionPoolDS.setPassword(mosa1c); } catch ( SQLException ex ) { // Catch SQL errors. //context.log( ex.toString( ) ); // log errors. } } This code creates a PooledConnection. - public static synchronized PooledConnection getPooledConnection(){ try{ pooledconn = connectionPoolDS.getPooledConnection(); }catch(SQLException sqle){ sqle.printStackTrace(); } return pooledconn; } In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); On an JSP Page: ServletContext ctx = getServletContext(); PooledConnection pc = (PooledConnection)ctx.getAttribute(pooled_conn); Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } Any help to solve this mystery would be very much appreciated. Kind Regards, Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OracleConnectionPoolDataSource creates too many connections
Rudi, I have two things to add that nobody seems to have mentioned. In my LoginServlet, I create a new PooledConnection, which I add to the Servlet Context: PooledConnection pc = ConnectionFactory.getInstance.getPooledConnection(); ServletContext ctx = getServletContext(); ctx.setAttribute(pooled_conn, pc); Gah! Why are you putting a database connection into the application context? This sounds like a concurrency nightmare! I think you want to put the /pool/ into the application scope, not a single connection. Connection con = pc.getConnection //do a few things with the connection try{ if (con != null){ con.close(); } // I'm assumingthis returns the connection to the Pool }catch(SQLException sqle){ sqle.printStackTrace(); } You need more try/catch blocks. conn.close should /always/ be in a finally block: Connection conn = null; // Declare your statements and resultsets, here, too try { conn = // whatever // Do stuff with connection } finally { // Close your statements and result sets, here, too if(null != conn) try { conn.close(); } catch (SQLException sqle) { /* log this exception somewhere */ } } Hope that helps, -chris signature.asc Description: OpenPGP digital signature