Note that there are some explanatory texts on larger screens.

plurals
  1. POConnecting to MySQL database java
    primarykey
    data
    text
    <p>I'm using some code for multi threaded MySQL system. It's working fine and will put entry's into my database in under half a second. My problem is, the rate at which my program will successfully connect and write to the database, is not great. Some of the time it will work fine and other times I'll receive this error, or similar: </p> <pre><code>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 27,697 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds 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:411) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3670) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3559) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4110) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379) at MySQL.putEntry(MySQL.java:46) at MySQL.main(MySQL.java:105) Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3119) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3570) ... 9 more </code></pre> <p>I'm really not sure why this happens? Executing too many statements from one address?? Anywho, here's my code:</p> <pre><code>private final ThreadedSQL sql; private final DatabaseConnection connection; private PreparedStatement statement; public Hiscores() { try { loadConfig(); } catch (IOException e) { e.printStackTrace(); } sql = new ThreadedSQL(config); connection = sql.getConnectionPool().nextFree(); } public void putEntry(final Player player) { try { statement = connection.getConnection().prepareStatement(QUERY(player)); statement.execute(); statement.closeOnCompletion(); } catch(Exception e) { e.printStackTrace(); } } </code></pre> <p>The code I've not included is irrelevant, uses java.sql.Connection. Does anyone have any idea why this is occuring? Thanks.</p>
    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.
    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