Bug #68743 SQLException: SQLState(S1000) vendor code(0)
Submitted: 22 Mar 2013 6:27 Modified: 30 Dec 2015 13:42
Reporter: Xiaofeng Liu Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:mysql-connector-java-5.1.24 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any
Tags: jdbc, SqlException

[22 Mar 2013 6:27] Xiaofeng Liu
Description:
Exception

DEBUG : SQLException: SQLState(S1000) vendor code(0)
DEBUG : 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
DEBUG : 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
DEBUG : 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
DEBUG : 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
DEBUG : 	at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:808)
DEBUG : 	at com.mysql.jdbc.ResultSetImpl.realClose(ResultSetImpl.java:7335)
DEBUG : 	at com.mysql.jdbc.ResultSetImpl.close(ResultSetImpl.java:927)
DEBUG : 	at com.mysql.jdbc.StatementImpl.realClose(StatementImpl.java:2585)
DEBUG : 	at com.mysql.jdbc.StatementImpl.close(StatementImpl.java:577)
DEBUG : 	at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:4234)
DEBUG : 	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3587)
DEBUG : 	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2536)
DEBUG : 	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2306)
DEBUG : 	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:839)
DEBUG : 	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
DEBUG : 	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
DEBUG : 	at java.sql.DriverManager.getConnection(DriverManager.java:525)
DEBUG : 	at java.sql.DriverManager.getConnection(DriverManager.java:171)
DEBUG : 	at com.mysql.jdbc.test.ConnectionTest.main(ConnectionTest.java:32)

How to repeat:
Set a LogWriter in DriverManger, then use it to get connection and run SQL. 

//code sample
DriverManager.setLogWriter(new java.io.PrintWriter(System.out));

Connection conn =DriverManager.getConnection("jdbc:mysql://localhost/quickstart", "root", "!QAZxsw2");
System.out.println(conn.getMetaData().getDatabaseProductName());

Suggested fix:
I think it is an exception here.

protected final MySQLConnection checkClosed() throws SQLException {

       if (c == null) {
	 throw SQLError.createSQLException(
  Messages.getString("ResultSet.Operation_not_allowed_after_ResultSet_closed_144")       , //$NON-NLS-1$
        SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
}

}
[25 Apr 2013 5:54] Alexander Soklakov
Hi Xiaofeng,

Thanks for your report.

Verified as described.
[12 Nov 2013 10:49] Sergiy Shyrkov
Hello,

the issue is still present in the mysql-connector-java-5.1.26.
The thing is that I've noticed quite many instances of the SQLException when profiling my application.
The stack trace is:

com.mysql.jdbc.ResultSetImpl.checkClosed()
  com.mysql.jdbc.ResultSetImpl.realClose(boolean)
    com.mysql.jdbc.ResultSetImpl.close()
      com.mysql.jdbc.StatementImpl.realClose(boolean, boolean)
        com.mysql.jdbc.PreparedStatement.realClose(boolean, boolean)
          com.mysql.jdbc.StatementImpl.close()
            org.apache.jackrabbit.core.util.db.DbUtility.close(Connection, Statement, ResultSet)

Actually, the exception is not needed at that point and we could perhaps save some resources and heap if not creating that exception at least in case of the reallyClose() method.

The method reallyClose()was changed after 5.1.19.
In 5.1.19 it was reading like:

  public synchronized void realClose(boolean calledExplicitly)
    throws SQLException
  {
    if (this.isClosed) {
      return;
    }
    try
    {
      if (this.useUsageAdvisor)
...

So it was not creating/catching any unneeded instances of SQLException (this.isClosed was enough).

Could this method now be modified to do a simple check (like in checkClosed())?

I.e.:

if (this.connection == null) {
    return;
}

Thank you in advance!

Kind regards
Sergiy

–
Sergiy Shyrkov
Product Development
--------------------------------
Jahia Solutions Group
web: http://www.jahia.com
---------------------------------
Jahia's next-generation, open source CMS stems from a widely acknowledged vision of enterprise application convergence – web, search, document, social and portal – unified by the simplicity of web content management.
[16 Jan 2014 14:26] Sergiy Shyrkov
Any status on the progress?
Thank you in advance!
[8 Apr 2014 22:12] Sergiy Shyrkov
Could you, please, verify if it is expected to provide a solution for this issue?
Could I be somehow helpful on this, by submitting a patch?

Thank you in advance!

Kind regards
Sergiy Shyrkov
[30 Dec 2015 13:42] Filipe Silva
Posted by developer:
 
Seems to be fixed in Connector/J 5.1.28 and above.

I'm closing this issue. Please feel free to reopen it or file a new one if you think something is missing.