Bug #77665 JDBC fails to connect with MySQL 5.0
Submitted: 9 Jul 2015 7:43 Modified: 7 Oct 2015 12:30
Reporter: sxq sxq Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.1.36 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: connetor/j, jdbc, regression

[9 Jul 2015 7:43] sxq sxq
Description:
when i upgrade connector/j from 5.1.35 to 5.1.36,the code can't work.
the exception is "Unknown system variable 'language'"

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestMysqlJdbc {

	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/CTG",
					"root", "123456");
			Statement sta = con.createStatement();
			ResultSet rs = sta.executeQuery(" SELECT * FROM t_user ");
			while (rs.next()) {
				System.out.println(rs.getString("Username"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}

receive:
java.sql.SQLException: Unknown system variable 'language'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2541)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2499)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1432)
	at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3870)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3284)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2293)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at com.mysql.test.jdbc.TestMysqlJdbc.main(TestMysqlJdbc.java:38)
[9 Jul 2015 9:03] sxq sxq
when i use mysql server 5.0.95,the exception happen;but when i use 5.5.38,the exception does not exist! so,i guess whether the reason is connector/j 5.1.36 does not compatible with server 5.0.95,the version 5.1.35 is compatible ?:D
[9 Jul 2015 10:13] MySQL Verification Team
Hello!

Thank you for the report.
Indeed, only issue observed with 5.1.36 when connecting 5.0.x( 5.1.36 has no issues with 5.1.76,5.5.46,5.6.27 and 5.7.8, 5.1.35 works with 5.0.96,5.1.76,5.5.46,5.6.27 and 5.7.8).

Thanks,
Umesh
[9 Jul 2015 10:14] MySQL Verification Team
// Schema used

GRANT ALL ON *.* TO 'ushastry'@'%';
create database if not exists test;
use test;
create table t1(id int not null,Username varchar(100));
insret into t1 values(1,'MySQL');

##
[root@fedora21 Downloads]# cat TestMysqlJdbc.java 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestMysqlJdbc {

	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			Connection con = DriverManager.getConnection("jdbc:mysql://x.x.x.x:15000/test",
					"ushastry", "");
			Statement sta = con.createStatement();
			ResultSet rs = sta.executeQuery(" SELECT * FROM t1; ");
			while (rs.next()) {
				System.out.println(rs.getString("Username"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}

##

[root@fedora21 Downloads]# javac -cp '.:mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar' TestMysqlJdbc.java
[root@fedora21 Downloads]# java -cp '.:mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar' TestMysqlJdbc
java.sql.SQLException: Unknown system variable 'language'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2541)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2499)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1432)
	at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3870)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3284)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2293)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at TestMysqlJdbc.main(TestMysqlJdbc.java:16)
[root@fedora21 Downloads]# 
[root@fedora21 Downloads]# javac -cp '.:mysql-connector-java-5.1.35/mysql-connector-java-5.1.35-bin.jar' TestMysqlJdbc.java
[root@fedora21 Downloads]# java -cp '.:mysql-connector-java-5.1.35/mysql-connector-java-5.1.35-bin.jar' TestMysqlJdbc
MySQL
[root@fedora21 Downloads]#
[21 Jul 2015 12:12] Jonas Nyrup
I observed the same problem when upgrading the connector from 5.1.35 to 5.1.36 on server 5.1.29-rc-community
[30 Jul 2015 16:40] Filipe Silva
Bug synopsis changed.
[4 Aug 2015 21:51] Pedro Mariano Dragon
i'm having this same problem! when o run the program to do a Login, in eclipse using mysql database, appears that same message error Unknown system variable 'language'.

how can i fix that?
[20 Aug 2015 22:54] Daniel So
Added the following entry to the Connector/J 5.1.37 changelog:

"Connecting to MySQL 5.0 and 5.1 using Connector/J 5.1.36 resulted in an SQLException, with a complaint for an 'Unknown system variable "language"'"
[24 Aug 2015 13:29] Filipe Silva
Hi Pedro,

If you can, you should update your database version. If not, I'll have to stick with Connector/J 5.1.35 until we release a fix for this.
[17 Sep 2015 15:31] Manuel Novoa
any news to solve this problem?

thanks
[27 Oct 2015 15:43] Jonas Nyrup
Hi Manuel

The bug should be fixed in Connector/J 5.1.37, see https://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1-37.html.

Unfortunately, the bug still hits me.

java.sql.SQLException: Unknown system variable 'language'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:959)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3870)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3806)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2470)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2617)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2546)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2504)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1370)
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3861)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3289)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2298)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
[27 Oct 2015 16:09] David Le Borgne
Using SQL Workbench/J, the problem is fixed with Connector/J 5.1.37, when connecting to MySQL 5.0.96 or 5.1.73.
[27 Oct 2015 16:42] Filipe Silva
Hi Jonas,

Care to detail? Which MySQL server version are you trying to connecting to?
[27 Oct 2015 20:08] Jonas Nyrup
Hi Filipe

Sure! Please let me know, if you need more information.

protocol_version	10
version			5.1.29-rc-community-log
version_comment		MySQL Community Server (GPL)
version_compile_machine	i686
version_compile_os	pc-linux-gnu
[28 Oct 2015 13:23] Filipe Silva
Hi Jonas,

In Connector/J 5.1.36 we improved the connection time. Sadly this introduced the inability to connect to very old MySQL servers, namely to early MySQL 5.0 and 5.1 versions. Connector/J 5.1.37 fixes this problem but only for MySQL 5.1.31 and above.

MySQL 5.1.29 is way too old and not even a GA release (first GA was MySQL 5.1.30). If possible, you should upgrade your server to the latest available version. If you are unable to do it then, I'm sorry to tell you this but, you'll have to stick with Connector/J 5.1.35.

If you *really* need this fixed, the best option for you is to open a new bug (don't forget to mention this bug# in the description) but mind that it will have very low priority since we are talking about connecting to very old servers and MySQL 5.1 is, in fact, EOL these days.

I hope you find the best solution for you. Let me know if you need more assistance.
[28 Oct 2015 14:48] Jonas Nyrup
Hi Filipe

Thanks a lot for the quick and detailed answer.
I'll poke our DBAs to upgrade it.
[10 Aug 2016 7:12] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=82516 marked as duplicate of this one.
[24 Jun 2019 9:06] MySQL Verification Team
Bug #95940 marked as duplicate of this one