gpt4 book ai didi

java - 只打印查询字符串的长度

转载 作者:太空宇宙 更新时间:2023-11-03 10:53:46 25 4
gpt4 key购买 nike

谁能告诉我以下连接有什么问题,我只是想将记录插入数据库,出于某种原因,每当我尝试运行我的程序时,它都会继续打印以下两件事:

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)

最近的堆栈跟踪:

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)

最佳答案

我不了解 MySQL,但大概您的日期至少需要用引号引起来——可能还需要附加类型转换。

           + " '2014-03-12 14:55:32'   , "

编辑:查看 this page我猜它可能看起来像:

+ " TIMESTAMP '2014-03-12 14:55:32' , "

但是我不知道你要插入的列的类型

编辑 2:

感谢 Emanual,我想补充一点,您还需要在插入内容中引用其他字符串:

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', "
+ " ) ";

关于java - 只打印查询字符串的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22368801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com