关于servlet中sql语句的问题

String sql="select * from t_log where name=? and pw=?";
在运行到这句的时候产生以下错误

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 '? and pw=?' at line 1

换成
String sql="select * from t_log"; 可以执行
其他的sql语句
String sql = "insert into t_log(name,pw) values(?,?)"; 也能执行

求解释,是不是where的用发错了啊

不是一个问题么,http://ask.csdn.net/questions/157182,用错了statement。

追加,改为String sql="select * from t_log where name=? "; 依然报错

where没用错啊,是不是你要查询的值不符合条件呢

这种是参数化查询语句,你没给执行语句的对象添加name和pw参数吧

String sql="select * from t_log where pw=?";
String sql="select * from t_log a where a.name=?";
这样试试

select * from t_log where name='名字' and pw='密码’直接参数拼接起来呢

这种SQL是属于PreparedStatement,需要这样使用:
PreparedStatement pstmt = conn.prepareStatement("select * from t_log where name=? and pw=?"); // 创建语句,里面的参数等可以用问号代替
pstmt.setString(1,"a");//给第一个问号赋值"a";
pstmt.setString(2,"b");//给第二个问号赋值"b";

pstmt.executequery();

先丢到客户端执行,看是否可以。

肯定不是运行到这句报的错吧,你执行这个sql时报的错,你之后在提交这个SQL之前,有没有给这两个问号复制 String sql="select * from t_log where name=? and pw=?";
在运行到这句的时候产生以下错误