DataSource misconfigured?
Hello Again Everyone! I know I have already sent out a message or three about this, but I need to resolve it pretty quickly. I found a work around, but I would like a sanity check from those of you who really understand this stuff. I included a method that I wrote to get Connections, You can see the old and the new along side each other. The "manual" method allows me to query till the cows come home.. The "Resource" method gives me 12 DB hits on 4.1.18 and 5 on 4.1.24 (tested on both solaris 8 and 9) before it appears to hang. Oddly enough I can't pinpoint what is hanging because I have added log statements to this method and it appears to be working.. but substituting those two lines below removes the issue, so I believe it is returning an invalid connection or something that I don't understand. Thanks for any time spent on reading this! / Method Start / public static Connection getConnection () throws Exception { Connection connection; try { /*** Old Version Context ctx = new InitialContext (); if ( ctx == null ) throw new Exception ("No Context"); DataSource ds; ds = (DataSource)ctx.lookup ("java:comp/env/jdbc/CIHDB"); if ( ds != null ) connection = ds.getConnection(); else { return null; }//end of else End of old version */ Class.forName ("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection ( "jdbc:mysql://localhost/cih", "User","PassWord"); }//end of try catch ( Exception e ) { throw (e); }//end of catch return connection; }//end getConnection /* Web.xml definition Resource reference to a factory for java.sql.Connection instance that may be used for talking to a particular database that is configured in the server.xml file jdbc/CIHDB javax.sql.DataSource Container /** server.xml factory org.apache.commons.dbcp.BasicDataSourceFactory username User password Password driverClassName com.mysql.jdbc.Driver url jdbc:mysql://localhost/cih removeAdandoned true removeAdandonedTimeout 120 MaxActive 50 MaxIdle 10 MaxWait 200 Steve Gums - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DataSource misconfigured?
Are you using a finally bock to close your connections? You might be reaching the maximum connections allowed in the pool for DBCP. Please provide an example of a query statement where you do try/catch/finally. If you are not checking if your connections are not null and then making a last ditch attempt to close them in the finally block, then that may very well be the problem. Also, your URL should have "?autoReconnect=true" appended to the "url" value since you are using MySQL. Jake At 10:29 PM 3/31/2003 -0700, you wrote: Hello Again Everyone! I know I have already sent out a message or three about this, but I need to resolve it pretty quickly. I found a work around, but I would like a sanity check from those of you who really understand this stuff. I included a method that I wrote to get Connections, You can see the old and the new along side each other. The "manual" method allows me to query till the cows come home.. The "Resource" method gives me 12 DB hits on 4.1.18 and 5 on 4.1.24 (tested on both solaris 8 and 9) before it appears to hang. Oddly enough I can't pinpoint what is hanging because I have added log statements to this method and it appears to be working.. but substituting those two lines below removes the issue, so I believe it is returning an invalid connection or something that I don't understand. Thanks for any time spent on reading this! / Method Start / public static Connection getConnection () throws Exception { Connection connection; try { /*** Old Version Context ctx = new InitialContext (); if ( ctx == null ) throw new Exception ("No Context"); DataSource ds; ds = (DataSource)ctx.lookup ("java:comp/env/jdbc/CIHDB"); if ( ds != null ) connection = ds.getConnection(); else { return null; }//end of else End of old version */ Class.forName ("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection ( "jdbc:mysql://localhost/cih", "User","PassWord"); }//end of try catch ( Exception e ) { throw (e); }//end of catch return connection; }//end getConnection /* Web.xml definition Resource reference to a factory for java.sql.Connection instance that may be used for talking to a particular database that is configured in the server.xml file jdbc/CIHDB javax.sql.DataSource Container /** server.xml factory org.apache.commons.dbcp.BasicDataSourceFactory username User password Password driverClassName com.mysql.jdbc.Driver url jdbc:mysql://localhost/cih removeAdandoned true removeAdandonedTimeout 120 MaxActive 50 MaxIdle 10 MaxWait 200 Steve Gums - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DataSource misconfigured?
Thanks Jacob! My problem was an unsuccessful close on one of my major servlets. Just a lame oversight on my part that caused a large headache. So for everyone else...REMEMBER to close your connections! Steve -Original Message- From: Jacob Kjome [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 01, 2003 7:39 AM To: Tomcat Users List Subject: Re: DataSource misconfigured? Are you using a finally bock to close your connections? You might be reaching the maximum connections allowed in the pool for DBCP. Please provide an example of a query statement where you do try/catch/finally. If you are not checking if your connections are not null and then making a last ditch attempt to close them in the finally block, then that may very well be the problem. Also, your URL should have "?autoReconnect=true" appended to the "url" value since you are using MySQL. Jake At 10:29 PM 3/31/2003 -0700, you wrote: >Hello Again Everyone! I know I have already sent out a message or three >about this, but I need to resolve it pretty quickly. I found a work around, >but I would like a sanity check from those of you who really understand this >stuff. I included a method that I wrote to get Connections, You can see the >old and the new along side each other. The "manual" method allows me to >query till the cows come home.. The "Resource" method gives me 12 DB hits on >4.1.18 and 5 on 4.1.24 (tested on both solaris 8 and 9) before it appears to >hang. Oddly enough I can't pinpoint what is hanging because I have added >log statements to this method and it appears to be working.. but >substituting those two lines below removes the issue, so I believe it is >returning an invalid connection or something that I don't understand. > >Thanks for any time spent on reading this! > >/ Method Start / >public static Connection getConnection () throws Exception { > > Connection connection; > try { > /*** Old Version > Context ctx = new InitialContext (); > if ( ctx == null ) > throw new Exception ("No Context"); > DataSource ds; > ds = (DataSource)ctx.lookup ("java:comp/env/jdbc/CIHDB"); > if ( ds != null ) > connection = ds.getConnection(); > else { >return null; > }//end of else > End of old version */ > Class.forName ("com.mysql.jdbc.Driver").newInstance(); > connection = DriverManager.getConnection ( > "jdbc:mysql://localhost/cih", > "User","PassWord"); > }//end of try > catch ( Exception e ) { > throw (e); > }//end of catch > return connection; >}//end getConnection > >/* Web.xml definition > > > Resource reference to a factory for java.sql.Connection > instance that may be used for talking to a particular > database that is configured in the server.xml file > > jdbc/CIHDB > javax.sql.DataSource > Container > > >/** server.xml > reloadable="true" crossContext="true"> > >prefix="localhost_CIH." suffix=".txt" >timestamp="true"/> > > auth="Container" > type="javax.sql.DataSource"/> > > > > factory > >org.apache.commons.dbcp.BasicDataSourceFactory > > > username > User > > > password > Password > > > driverClassName > com.mysql.jdbc.Driver > > > url > jdbc:mysql://localhost/cih > > > removeAdandoned > true > > > removeAdandonedTimeout > 120 > > > MaxActive > 50 > > > MaxIdle > 10 > > > MaxWait > 200 > > > > >Steve Gums > > >- >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]