Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

java - Stumped SQL Exception for JDBC

I'm trying all I can to get a JDBC to work, the only thing that is stumping me right now is this exception, which I have no idea about:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1049)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1890)
    com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3523)
    com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2386)
    com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
    com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
    com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:374)
    com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    java.sql.DriverManager.getConnection(libgcj.so.10)
    java.sql.DriverManager.getConnection(libgcj.so.10)

I'm using this to connect...

Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "username", "password");

Thanks a lot!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Those are the relevant parts:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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
    ...
    com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1890)
    ...
    java.sql.DriverManager.getConnection(libgcj.so.10)

Those question marks indicate a serious character encoding problem during the query to configure the client charset.

As first try, open the my.cnf file and ensure that the following two entries are present:

character_set_server=utf8
collation_server=utf8_general_ci

As second try, replace the GCJ by OpenJDK or Oracle (Sun) JDK which are way more robust. The GCJ is namely known to have its oddities.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...