Note that there are some explanatory texts on larger screens.

plurals
  1. POJDBC : Unable to connect second time
    primarykey
    data
    text
    <p>Hi All I am trying to connect a data base. below i have given the code. I am able to connect to data base but unable to connect 2nd time if difference between 1st time and 2nd time is greater then "wait time out" of mysql data base. I am using mysql data base. I am getting "Communications link failure" problem wait_timeout is 10 sec (for convenience) it is 8 hour for my DB I am giving you code </p> <pre><code>public class DatabaseManager { private static Connection jConn; private static DatabaseManager manager; public Boolean getUser(){ Statement jStmt = null; ResultSet rs = null; try { String query = "SELECT * FROM USER "; System.out.println(query); jStmt = jConn.createStatement(); rs = jStmt.executeQuery(query); while (rs.next()) { } }catch (Exception e) { e.printStackTrace(); return false; } return true; } public static synchronized DatabaseManager getInstance() { if (manager == null) { try { manager = initialize(); } catch (DatabaseInitializationException e) { // e.printStackTrace(); // throw new RuntimeException("Database Initialization // Exception"); } } return manager; } private static DatabaseManager initialize() throws DatabaseInitializationException { try { Class.forName(serverSrv.readPropertyValue("Srver_Path", "DBdriver")); } catch (ClassNotFoundException e) { throw new DatabaseInitializationException(e.getMessage()); } try { jConn = DriverManager.getConnection("DB_URL","user","password"); System.out.println("Excecuted initialize() for Database "); } catch (SQLException e) { throw new DatabaseInitializationException(e.getMessage()); } return new DatabaseManager(); } } </code></pre> <p>AND I am testing like</p> <pre><code> public static void main(String[] args) { long st = System.currentTimeMillis(); long end ; DatabaseManager dm = DatabaseManager.getInstance(); if( dm.getUser() ) System.out.println("success"); else System.out.println("failed.."); do{ end = System.currentTimeMillis(); }while( (end-st)&lt;12*1000 ); if( dm.getUser() ) System.out.println("success"); else System.out.println("failed.."); } </code></pre> <p>and it is giving exception like </p> <pre><code>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2873) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2763) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3299) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2537) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2466) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383) at mypackage.db.DatabaseManager.getUser(DatabaseManager.java:127) at mypackage.test.Test.main(Test.java:23) Caused by: java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2329) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2774) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload