困扰 JDBC 的 SQL 异常
我正在尽我所能让 JDBC 工作,现在唯一困扰我的是这个异常,我不知道:
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)
我正在使用它来连接......
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "username", "password");
非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些是相关部分:
这些问号表示在查询配置客户端字符集期间存在严重的字符编码问题。
第一次尝试时,打开 my.cnf 文件并确保存在以下两个条目:
作为第二次尝试,将 GCJ 替换为 OpenJDK 或 Oracle (Sun) JDK 更加健壮。众所周知,GCJ 有其怪异之处。
Those are the relevant parts:
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:
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.