java - Connection of c3p0 throws exception after MySQL timeout expired -


I use the library c3p0 of version 0.9.2.1 to create a connection pool in the web application. After MySQL timeout I get exception:

"HTTP Status 500 - Last successfully received from the server packet was 627,301 milliseconds before. The last packet was sent successfully to the server 627 302 milliseconds before. 'Wait_timeout' is the server more than configured value. you enlarge the configured client timeout values ​​or connector / J connection property using 'autoReconnect = true, your application Should end and / or test the validity of connection prior to use. "To avoid this problem."

I tried adding JDBC URL to an auto-reconnect parameters but there is no effect I therefore, the way I use the connection pool in your application:

for the test I have set wait_timeout of MySQL 180 seconds

  set @@ global.wait_timeout = 180; Show global variables like "Wait_timeout"; + --------------- + ------- + | Variable_name | Price | + --------------- + ------- + | Wait_timeout | 180 | + --------------- + ------- +  

and further the next piece of code

C3p0.properties

  # JDBC parameters Ommited are # Basic pool configuration c3p0.initialPoolSize = 5 c3p0.minPoolSize = 5 c3p0.maxPoolSize = 50 c3p0.acquireIncrement = 5 # age of connection c3p0.maxConnectionAge = 100 c3p0.maxIdleTime = 90 # connection c3p0.idleConnectionTestPeriod configuring test = 30 c3p0.testConnectionOnCheckin = true c3p0.preferredTestQuery = SELECT 1  

DBConnectionUtil.java

  Started with public class DBCNNTUETE {// R.P.P.P.P. Properties Private Static Combo Pulheddatasource DS = New Combo Puleddatassor (); Public stable ComboPooledDataSource getConnectionPool () {return DS; } Public Static Zero Destroy Console () {ds.close (); } Public static connection match connection () throws SQLException {returns ds.getConnection (); }}  

UserDAO.java

  public class UserDAO {Private connection connection; Public user () throws SQL Connection {connection = DBConnectionUtil.getConnection (); } Public user search (integer ID) throws SQLException {user user = null; Ready: Static PS = connection.prepareStatement ("Select * from user 'where id =?"); Ps.setInt (1, id); Results set rs = ps.executeQuery (); If (rsnext ()) {user = new user (); User.setId (rs.getInt ("id")); User.setName (rs.getString ("NAME")); User.setUsername (rs.getString ("user name")); User.setPassword (rs.getString ("password")); User.setParentId (rs.getInt ("PARENT_ID")); } Rs.close (); Ps.close (); Return user; }}  

DAOUtil.java

  public class DAOUtil {Private stationary userDAO userDAO; Public Static Usergay Gouşdaro () {Return UserDeo; } Fixed {try {userDAO = new user ()); } Hold (eclipse e) {new runtime exception (e); For example, when I call DAOUtil.userDAO.find (id) throws an exception that was described above.  

Can you please help me realize what I am doing, please? Note: I can not change MySQL ini file.

Try to discontinue connections in your Dao class and ask from the connection pool for every request from the database A new.

  Connection Con? Try {con = DBConnectionUtil.getConnection (); // some code here} at the end {if (con! = Null) {con.close (); }  

and it is not safe to have connection as an object area, it is better to use it as a local variable, because the connection thread is not secure


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -