import java.sql.*; /* *the environment C:\Temp>java -version java version "1.4.2_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06) Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode) >mysql --version >mysql Ver 14.3 Distrib 4.1.1-alpha, for pc-linux (i686) * the command lines to compile and test it * @echo off javac -classpath c:\mystocks\mysql-connector-java-3.1-nightly-20040524-bin.jar TestQuery.java java -classpath c:\mystocks\mysql-connector-java-3.1-nightly-20040524-bin.jar;. TestQuery %1 * the TestQuery takes option argument "true" . If "true" is passed * as an argument, compression will be used * run the following script to create and test the database * mysql --batch --force < input_script * -- start of sql script --- drop database if exists test_sql_compress; create database test_sql_compress; create table test_sql_compress.present (first VARCHAR(30), last VARCHAR(30)); insert ignore into test_sql_compress.present Values('MySQL', 'Connector'); insert ignore into test_sql_compress.present Values('Testing', 'UseCompress'); -- dont create another table here -- but try to select from absent table -- select * from test_sql_compress.absent; select * from test_sql_compress.present; -- end of sql script --- The problem : run this command without "true" and you the program runs fine. Run it with "true" as argument and the connection to the server drops/hangs. UseCompression=true doesn't work. SQLException: Server connection failure during transaction. Due to underlying ex ception: 'java.sql.SQLException: Communication link failure message from server: "Unknown command"'. ** BEGIN NESTED EXCEPTION ** java.sql.SQLException MESSAGE: Communication link failure message from server: "Unknown command" STACKTRACE: java.sql.SQLException: Communication link failure message from server: "Unknown command" at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2441) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1396) at com.mysql.jdbc.Connection.ping(Connection.java:3207) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1799) at com.mysql.jdbc.Connection.execSQL(Connection.java:2248) at com.mysql.jdbc.Connection.execSQL(Connection.java:2199) at com.mysql.jdbc.Statement.executeQuery(Statement.java:1182) at TestQuery.do_select(TestQuery.java:16) at TestQuery.send_queries(TestQuery.java:82) at TestQuery.(TestQuery.java:60) at TestQuery.main(TestQuery.java:32) ** END NESTED EXCEPTION ** Attempted reconnect 3 times. Giving up. */ public class TestQuery { Connection con; Statement stmt; // replace these next 3 statements with your username, passwd // and your server address static String username = "USERNAME"; static String passwd = "PASSWRORD"; static String url="jdbc:mysql://your.server.addr.here:3306/?autoReconnect=true&useCompression="; private void do_select(String query) throws Exception { try { stmt = con.createStatement(); System.out.println("statement = " + query); ResultSet result = stmt.executeQuery(query); System.out.println("======= Result query = " + query + " ===== "); while (result.next()) { String name = result.getString(1) + " " + result.getString(2); System.out.println(name); } stmt.close(); System.out.println("======End of query ======="); } catch (Exception e) { throw e; } } public static void main(String args[]) { TestQuery tq = new TestQuery(args); } public TestQuery (String args[]) { String query; String newurl; try { Class.forName("com.mysql.jdbc.Driver"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { if (args.length == 1 && args[0].equals("true")) { newurl = url + "true"; } else { newurl = url + "false"; } System.out.println("URL = " + newurl); System.out.print("Trying to connect ... "); con = DriverManager.getConnection (newurl, username, passwd); System.out.println("connected!"); send_queries(); con.close(); } catch(SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } } private void send_queries() { String queries[] = new String[2]; queries[0] = new String("SELECT * FROM test_sql_compress.absent"); queries[1] = new String("SELECT * FROM test_sql_compress.present"); for (int i = 0; i < queries.length; i++) { try { if (queries[i] != null) do_select(queries[i]); } catch (SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } catch (Exception e) { System.err.println(e.getMessage()); } } } }