code_junkie

Weird JDBC executeQuery exception

Nov 13th, 2011
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. public Object RunQuery(String query) throws Exception{
  2. System.out.println("Trying to run query");
  3. Statement stmt = null;
  4. ResultSet rs = null;
  5. try {
  6. stmt = conn.createStatement();
  7. System.out.println("Got Statement");
  8. rs = stmt.executeQuery(query);
  9. System.out.println("Query executed");
  10. ...
  11.  
  12.  
  13. } catch (SQLException ex) {
  14. // handle any errors
  15. System.out.println("SQLException: " + ex.getMessage());
  16. System.out.println("SQLState: " + ex.getSQLState());
  17. System.out.println("VendorError: " + ex.getErrorCode());
  18. }
  19. catch (Exception ex) {
  20. System.out.println("Exception: " + ex.getMessage());
  21. }
  22. finally {
  23. if (rs != null) {
  24. try {
  25. rs.close();
  26. } catch (SQLException sqlEx) {
  27. } // ignore
  28. rs = null;
  29. }
  30. if (stmt != null) {
  31. try {
  32. stmt.close();
  33. } catch (SQLException sqlEx) {
  34. } // ignore
  35. stmt = null;
  36. }
  37. return ret;
  38. }
  39. }
  40.  
  41. query = "SELECT * FROM smalltable"
  42.  
  43. query = "SELECT * FROM bigtable"
  44.  
  45. >Exception occurred in target VM: Communications link failure Last packet sent to the server was 0 ms ago.
  46. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago.
  47.  
  48. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  49.  
  50. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  51.  
  52. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  53.  
  54. at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  55.  
  56. at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
  57.  
  58. at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
  59.  
  60. at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009)
  61.  
  62. at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895)
  63.  
  64. at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438)
  65.  
  66. at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
  67.  
  68. at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
  69.  
  70. at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
  71.  
  72. at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
  73.  
  74. at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
  75.  
  76. at RunQuery
  77. Caused by: java.net.SocketException: Software caused connection abort: recv failed
  78.  
  79. at java.net.SocketInputStream.socketRead0(Native Method)
  80.  
  81. at java.net.SocketInputStream.read(SocketInputStream.java:129)
  82.  
  83. at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:157)
  84.  
  85. at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
  86.  
  87. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2452)
  88.  
  89. at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2962)
  90.  
  91. ... 9 more
  92.  
  93. jdbc:mysql://localhost?user=root&password=password
Add Comment
Please, Sign In to add comment