java中的preparedStatement SQL错误
我执行以下代码时出错java中的preparedStatement SQL错误,java,mysql,sql,jdbc,prepared-statement,Java,Mysql,Sql,Jdbc,Prepared Statement,我执行以下代码时出错 preparedStatement=connection.prepareStatement(“从fpp_报警“+”中选择*其中id=?”; 准备好的报表。设置字符串(1,id)//字符串id=“4” ResultSet ResultSet=preparedStatement.executeQuery(); 错误是: You have an error in your SQL syntax; check the manual that corresponds to your
preparedStatement=connection.prepareStatement(“从fpp_报警“+”中选择*其中id=?”;
准备好的报表。设置字符串(1,id)//字符串id=“4”
ResultSet ResultSet=preparedStatement.executeQuery();
错误是:
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 '= '4'' at line 1.
我在这里看到了类似的问题:
但是,我在代码中找不到mysql的“保留字”。在mysql中执行此查询时也是正确的。连接时,您会看到SQL语句中的
fpp\u alarm
和where
之间没有空格
select * from fpp_alarmwhere id = ?
在SQL文本字符串中添加该空格,可以在
fpp\u报警
之后,也可以在之前,其中
之间没有空格
pp_alarm"+ "wher
应该是
…pp\u报警“+”其中…
假设
String query="select * from fpp_alarm"+ "where id = ?";
当对其进行评估时,结果是
select * from fpp_alarmwhere id = ?
// the + sign concatenates the two pieces of String
// into one with no space between them you can either solve it by doing this
String query="select * from fpp_alarm "+ "where id = ?"; // space after fpp_alarm
但我并不认为+在这里有什么用处,只是像这样尝试一下
String query="select * from fpp_alarm where id = ?";
此处缺少一个空格
fpp_alarm“+”,其中代码片段仅用于HTML/JavaScript,请勿在与HTML无关的问题中使用它们/JavaScript@sparkon,然后您将查询呈现为这样“…pp_alarm where…”,现在它呈现为“.pp_alarmwhere…”我的错误其正确性我注意不到where之前的空格。