我正在尝试运行jdbc查询。这是我的代码
Timestamp timeStamp = new Timestamp(svnLog.getTime().getTime());
String query = "Insert into transaction (RevisionId, AuthorId, LogMessage, Time) values (?,?,?,?) ";
System.out.println("The query is " + query + svnLog.getRevisionId() + "," + svnLog.getAuthorId() + "," + svnLog.getLogMessage() + "," + timeStamp);
try {
PreparedStatement stmt = connManager.getConnection().prepareStatement(query);
stmt.setLong(1, svnLog.getRevisionId());
stmt.setString(2, svnLog.getAuthorId());
stmt.setString(3, svnLog.getLogMessage());
stmt.setTimestamp(4, timeStamp);
System.out.println("After binding " + stmt.toString());
这会引发以下异常。
After binding com.mysql.jdbc.PreparedStatement@478e4327: Insert into transaction (RevisionId, AuthorId, LogMessage, Time) values (214,'mknauer','Initial import.','2007-03-01 06:39:21.128')
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
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1402)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1317)
at dataminer.db.Transactiondb.addTransaction(Transactiondb.java:40)
at dataminer.svn.download.SVNLogManager.processTransaction(SVNLogManager.java:45)
at dataminer.svn.download.SVNLogManager.processSvnLog(SVNLogManager.java:26)
at dataminer.svn.download.SVNHistoryDownloadMgr.main(SVNHistoryDownloadMgr.java:160)
我在绑定后打印了准备好的声明。我在命令行上运行时打印的查询工作正常。我在其他一些帖子中看到了这个错误,其中解决方案是更改my.cnf文件以进行字符编码。我将这两行添加到此文件
character_set_server=utf8
collation_server=utf8_general_ci
它没有解决错误。