JDBC准备语句不起作用

时间:2014-03-08 13:24:07

标签: java mysql sql swing jdbc

以下jdbc代码给出错误MySQLSyntaxErrorException: You have an error in your SQL syntax;。帮我找到它。

   String selectqry="select * from raildb"+ "WHERE id=?"; 
   Class.forName("com.mysql.jdbc.Driver");
   Connection con=DriverManager.getConnection(host,uName,uPass);              
   ps1=con.prepareStatement(selectqry);
   ps1.setInt(1,MyModel.idno);        
   ResultSet rs=ps1.executeQuery();

2 个答案:

答案 0 :(得分:3)

为查询添加空格

String selectqry="select * from raildb "+ "WHERE id=?"; 
                                      ^

答案 1 :(得分:1)

tablename 和关键字

之间的sql查询中添加空格
String selectqry="select * from raildb "+ " WHERE id=?";