我试图用Java和JDBC时间戳查找表中的SQL,但是当我插入时间戳到查询字符串我在小时图中得到一个错误的语法时才:在JDBC查询字符串中的SQL语法错误?
String queryString = "select " + tag + " from WATER_RUNTIME_VALUES
where Time_Stamp = 2015-06-150 8:58:00.0000000";
ResultSet rs = statement.executeQuery(queryString);
这里是错误:时间值
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '10'. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515) at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792) at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:616) at bandon.scada.core.InitConn.calculateHourlyTotal(InitConn.java:58) at bandon.scada.core.InitConn.dbConnect(InitConn.java:36) at bandon.scada.core.InitConn.main(InitConn.java:24)
什么是标签的内容? – Jens
考虑使用参数化查询。这将避免需要将日期文字放在引号中并格式化日期文字字符串。 –