Mysql中查询语句中占位符问题
天仲子 2013-11-28 07:26:40 想用占位符实现页面对servlet传参,再对Mysql数据库进行查询,可是一直不知道哪错了
代码
Connection conn = DriverManager.getConnection(url,username,password);
String sql = "select * from tb_book where name=? or author=?";
PreparedStatement ps= conn.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2,author);
ResultSet rs = ps.executeQuery(sql);
出错信息
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 '? or author=?' at line 1