Java连接SQL server数据库时报出 com.microsoft.sqlserver.jdbc.SQLServerException: 必须声明表变量 "@P0"。错误
程序员文章站
2024-02-20 10:46:34
...
String sql ="SELECT DISTINCT* FROM ? where 车速!=0 and 时间 between ? and ? order by 车速";//预处理语句
PreparedStatement stat = con.prepareStatement(sql);
stat.setString(1, "[KaKou].[dbo].[第一组数据]");
stat.setString(2, "2019-10-19");
stat.setString(3, "2019-10-20");
ResultSet res = stat.executeQuery();
假期老师的作业,正常连接的时候时正常的,但是使用预处理的时候会报错,大神求解答
错误的是:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: 必须声明表变量 "@P0"。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
上一篇: Cascade
下一篇: Java并发控制机制