数据库占位符问题
小弟刚接触占位符,遇到如下问题:
String sql = "select Deid,Dename,Password,Phone,Email from defenders where Deid=?;";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,Deid);//Deid为字串
rs = ps.executeQuery(sql);//执行到这一句报异常
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 '?' at line 1
望大侠帮忙指点。。。。。
------解决方案--------------------
注入方式是不需要带SQL的,带SQL是Statement的方法。
rs = ps.executeQuery(sql);//执行到这一句报异常
=》
rs = ps.executeQuery();