【发布时间】:2014-03-13 04:00:10
【问题描述】:
谁能告诉我下面的连接有什么问题,我只是想将记录插入数据库,出于某种原因,每当我尝试运行我的程序时,它只会继续打印以下两件事:
the length of the Query String for Error is :506
Value of Catch inside Catch with SQLException ex1:true
我的代码如下:
Statement InsertRemoteResultsErrorLogStmt = null;
ResultSet SelectErrorLogRS = null;
Connection connRemoteforCatch = null;
try {
String QueryStringInsertIntoErrorLogs = "";
connRemoteforCatch = DriverManager.getConnection("jdbc:mysql://xx.xx.x.xxx:3306/test", MainUser, MainPass);
QueryStringInsertIntoErrorLogs = " INSERT INTO simplequeue.errorlogs "
+ " ( "
+ " ErrorNumber_int, "
+ " Created_dt, "
+ " Subject_vch, "
+ " Message_vch, "
+ " TroubleshootingTips_vch, "
+ " CatchType_vch, "
+ " CatchMessage_vch, "
+ " CatchDetail_vch, "
+ " Host_vch, "
+ " Referer_vch, "
+ " UserAgent_vch, "
+ " Path_vch, "
+ " Querystring_vch "
+ " ) "
+ " VALUES "
+ " ( "
//+ " NULL, " // ErrorLogIdInt
+ " 2002 , " // ErrorNumber_int
+ " 2014-03-12 14:55:32 , "
+ " SimpleX Error Notification, "
+ " Error Simple X Queue, "
+ " No Troubleshooting Tips Specified, "
+ " testgetsqlstate , "
+ " testgetmessage ,"
+ " NULL, "
+ " ebmdevii.messagebroadcast.com,"
+ " NULL, "
+ " CFSCHEDULE, "
+ " NULL, "
+ " DBSOURCE=BishopDev, "
+ " ) ";
System.out.println("the length of the Query String for Error is :" + QueryStringInsertIntoErrorLogs.length());
InsertRemoteResultsErrorLogStmt = connRemoteforCatch.createStatement();
InsertRemoteResultsErrorLogStmt.executeUpdate(QueryStringInsertIntoErrorLogs);
} catch (SQLException ex1) {
System.out.println("Stacktrace below:");
ex1.printStackTrace();
System.out.println("Value of Catch inside Catch with SQLException ex1:" + connRemoteforCatch.isValid(2));
}
这是我的堆栈跟踪:
Stacktrace below:
com.mysql.jdbc.exceptions.jdbc4.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 '14:55:32 , SimpleX Error Notification, Error Simple X Queue, No Troubleshoo' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
at mypackagename.Myclassreader.call(Myclassreader.java:492)
at mypackagename.Myclassreader.call(Myclassreader.java:25)
虽然它在第一行显示 SQL 语法错误,但我在 MySQL Workbench 中使用了相同的 SQL 查询并成功插入了记录。而且我的 Java 程序中似乎没有任何语法错误。请指教
更新的堆栈跟踪:
Stacktrace below:
com.mysql.jdbc.exceptions.jdbc4.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 'Error Notification, Error Simple X Queue, No Troubleshooting Tips Specified, ' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
最近的 Stacktrace:
com.mysql.jdbc.exceptions.jdbc4.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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
at ebmextractor.Myclassreader.call(Myclassreader.java:493)
at ebmextractor.Myclassreader.call(Myclassreader.java:25)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1259)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
【问题讨论】:
-
添加堆栈跟踪而不是注释掉怎么样,这样我们就可以看到问题所在了?注释打印行并取消注释堆栈跟踪并发布结果。
-
你能告诉我们堆栈跟踪吗?取消注释
ex1.printStackTrace(); -
我认为您需要阅读
Connection#isValid上的文档以了解它告诉您的内容... -
@Acapulco 已添加!请检查 !谢谢