Bug #1904 JDBC driver 3.0.9 does not work with 4.1 server
Submitted: 20 Nov 2003 12:33 Modified: 14 Jan 2004 15:19
Reporter: Eric Nielsen Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.0.9 OS:Any (all)
Assigned to: Mark Matthews CPU Architecture:Any

[20 Nov 2003 12:33] Eric Nielsen
Description:
Currently, there is not a version of the JDBC driver that works against a 4.1 server.  It appeared in the change history for 3.0.9 that the 4.1 server protocol changes had been backported in 3.0.9, but I get the error below when I try to connect to a 4.1 server.  Some google searches I ran turned up at least one other person who has noted the same problem.  Thanks -Eric

sqlstate = S1000
java.sql.SQLException: General error,  message from server: "Unknown character set: 'danish'"
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
        at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1070)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2027)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:1996)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:1977)
        at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:2680)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:1750)
        at com.mysql.jdbc.Connection.<init>(Connection.java:562)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:361)
        at java.sql.DriverManager.getConnection(DriverManager.java:543)
        at java.sql.DriverManager.getConnection(DriverManager.java:194)
        at Eric.main(Eric.java:19)

How to repeat:
Use the following java program with the 3.0.9 JDBC driver, and a 4.1 server.

import java.sql.*;

public class ConnectTest
{
    static {
      try {
         System.out.println("Please wait...initializing...");
         Class.forName("com.mysql.jdbc.Driver").newInstance();
      } catch (Exception e) {
         e.printStackTrace();
      }
    }

  public static void main(String args[])
  {
    Statement stmt = null;
    Connection targetCon = null;
    try {
      targetCon = DriverManager.getConnection("jdbc:mysql://mrhat/test","testuser","west");
      System.out.println("Connected...");
    } catch (SQLException e) {
      System.out.println("sqlstate = " + e.getSQLState() );
      e.printStackTrace();
    }
  }
}

Suggested fix:
Unknown.  I realize that 4.1 is still in alpha state, but it'd sure be nice to have a JDBC driver to test with.  We are looking at a port of many, many TBs of data spanning many databases to MySQL (or some other DB2/Oracle alternative), but our application is 100% java.  I need 4.1 for subquery support, so I'm kind of stuck in limbo on validating that a near-term version on MySQL will work for us.
[20 Nov 2003 12:43] Mark Matthews
I've seen this error reported once by one other person, but not have been able to repeat it.

We have many customers using both Connector/J 3.0.x and Connector/J 3.1.x in development who have not reported this problem either.

Can you post your my.cnf or your startup options to mysqld? Your options must have something different in them than what others are using which is causing this bug to appear.

You also don't say which 4.1 server you are using. Is it 4.1.0? On what platform? Is it something you've compiled from the bk tree? If you are using 4.1.0, you should probably stick to an older driver like Connector/J 3.1.0, as that is the driver that was tested against MySQL-4.1.0 (newer drivers like 3.0.8, 3.0.9 and pre-releases of 3.1.x are designed to be used with what is in the BK tree currently for MySQL-4.1, which is destined to be MySQL-4.1.1).
[20 Nov 2003 14:11] Eric Nielsen
java program to recreate ResultSet.getInt(1) problem

Attachment: Eric.java (application/octet-stream, text), 980 bytes.

[20 Nov 2003 14:20] Eric Nielsen
I just double-checked rpm -qa to be sure that I have the MySQL-server-4.1.0-0 rpm installed.  It's the 4.1 rpm I downloaded from mysql.com.  I'm currently running on RedHat 8 (Intel).  I never set up a my.cnf, but here are the startup options it gets when I start with "/etc/rc.d/init.d/mysql start":

/usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/mrhat.int.westgroup.com.pid

/usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/mrhat.int.westgroup.com.pid --skip-locking

I've tried the 3.1.0 driver, but I have problems with that too.  That's why I tried the 3.0.9 driver.  With 3.1.0,  I get the following error on a ResultSet.getInt(1) call:

java.sql.SQLException: Invalid value for getInt() - ''
        at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1348)
        at Eric.main(Eric.java:32)

I attached a simple java program (Eric.java) that can reproduce the getInt() problem.  The underlying table has just a single int column and 1 row of data.   I can post a different bug on this since it's a different problem if you'd like - just let me know.
[20 Nov 2003 14:46] Mark Matthews
Can you try to build MySQL-4.1 from BitKeeper? It's more important to see if this error occurs with the current MySQL-4.1 sources, because there are lots of changes Since 4.1.0 in the MySQL protocol that make backwards-compatibility difficult, and considering that 4.1.0 was a first ALPHA drop, we have to consider whether it is worth it to fix newer code to support older _ALPHA_ code.
[24 Nov 2003 10:22] Eric Nielsen
I got the source from bitkeeper and it all built fine (I had to upgrade bison, but otherwise very painless).  The err log says it's running at 4.1.1-alpha, so I think my install is good.  I can query my database via command line.  However, now I get a different error from the 3.1-alpha driver:

sqlstate = 08S01
java.sql.SQLException: Communication link failure: Bad handshake
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:815)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:1585)
        at com.mysql.jdbc.Connection.<init>(Connection.java:524)
        at com.mysql.jdbc.Driver.connect(Driver.java:359)
        at java.sql.DriverManager.getConnection(DriverManager.java:512)
        at java.sql.DriverManager.getConnection(DriverManager.java:194)
        at Eric.main(Eric.java:19)
java.lang.NullPointerException
        at Eric.main(Eric.java:27)

Is there some new Connector/J code I should get to match up well with 4.1.1-alpha?  If so, how/where can I get it.  Thanks -Eric
[24 Nov 2003 10:29] Mark Matthews
You need to use a nightly snapshot of the 3.1 series if you want to use MySQL-4.1.1 with Connector/J 3.1.x.

See http://downloads.mysql.com/snapshots.php
[24 Nov 2003 10:31] Mark Matthews
Connector/J 3.0.9 _should_ work with MySQL-4.1.1 as well. Can you try a nightly snapshot of the 3.0.x series? (3.0.9 works here with MySQL-4.1.1 on my development system).
[24 Nov 2003 10:44] Eric Nielsen
Ta-da!  The 11/23 snapshot works.  This should get me going.  Thanks for the help!  -Eric
[14 Jan 2004 15:19] Mark Matthews
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/