Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Unanswered: You have an error in your SQL syntax; check the manual that corresponds to your MySQL

    Hi All,

    I have installed ubuntu 9 and downloaded mysql-server, JDBC connector and Eclipse 3.2 via synaptic Manager. The versions I have

    mysql-server 5.1 (5.1.31 ubuntu 2)
    mysqlclient 5.1 (5.1.31 ubuntu 2)
    libmysql-java 5.1.6 JDBC (mysql-connector-java-5.1.6-bin.jar)
    ubuntu 9

    I was testing a simple code to check if a connection with a test database is established or not on mysql server but I keep receiving this error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1

    I am using the username root and the password that I put during mysql installation. The same code is working fine on my WIndows XP installation (mysql 5.1 and jdbc connector 5.1) with no errors.

    Why am I getting this problem ? I am not running any SQL query in the code!!!

    Is there a version conflict with current ubuntu packages?

    The whole code is listed below from a sun jdbc tutorial.


    import java.sql.Connection;
    import java.sql.DriverManager;

    public class Connect {

    public static void main(String args[]) {
    Connection con = null;

    try {
    String username = "root";
    String password = "pwd123";
    String url = "jdbc:mysql://localhost:3306/mysql";
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    con = DriverManager.getConnection(url, username, password);
    System.out.println("Connection Established.");
    }
    catch(Exception e) {
    System.err.println("Cannot Connect to DB. Exception: " + e.getMessage());
    }

    finally
    {
    if(con != null)
    {
    try
    {
    con.close();
    }

    catch(Exception e) {}
    }
    }
    }
    }

    Thanks

  2. #2
    Join Date
    May 2007
    Posts
    80
    what is the exact trace of the exception ?
    use e.printStackTrace();

    when you get the linenumber where the error occurs that will tell you where to look further.

  3. #3
    Join Date
    Aug 2009
    Posts
    2
    com.mysql.jdbc.exceptions.MySQLSyntaxErrorExceptio n: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1026)
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:19 36)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2536)
    at com.mysql.jdbc.ConnectionImpl.configureClientChara cterSet(ConnectionImpl.java:1751)
    at com.mysql.jdbc.ConnectionImpl.initializePropsFromS erver(ConnectionImpl.java:3425)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2045)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:718)
    at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:298)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:282)
    at java.sql.DriverManager.getConnection(libgcj.so.90)
    at java.sql.DriverManager.getConnection(libgcj.so.90)
    at Connect.main(Connect.java:14)

  4. #4
    Join Date
    May 2007
    Posts
    80
    The error occurs at the moment of establishing a connection, which is refused.

    Some possibilities:

    a) UNIX environments are case sensitive, Windows isn't, make sure you consistently use the same case.
    b) you are not allowed to access the port because of some firewalll setting
    c) mysql refuses a connection because for some reason the username is not allowed access, which would be strange for "root" but there you go.

    Don't think it's actual SQL syntax, more a case of not getting through.

  5. #5
    Join Date
    May 2007
    Posts
    80
    Have a read through this:
    MySQL :: Problem with connecting to MySQL server

    seems to have done the trick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •