mysql使用PreparedStatement的一个奇怪问题???
public boolean IsExistStudent(String username)throws
SQLException{
boolean flag=false;
String sql= "select * from user where username=? ";
Connection conn=DBconnect.getConnection();
PreparedStatement pstat=null;
pstat=conn.prepareStatement(sql);
pstat.setString(1,username);
ResultSet rs=null;
rs=pstat.executeQuery(sql);
if(rs.next()){
flag=true;
}
DBconnect.close(rs, pstat, conn);
return flag;
}
使用的是mysql5.0 错误提示: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 1StudentControl Servlet error: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 1StudentControl Servlet error: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
可是这个方法却能正常运行
public void addStudent(Student s)throws SQLException{
String sql= "insert into user values(?,?,?,?,?,?) ";
Connection conn=DBconnect.getConnection();
PreparedStatement pstat=conn.prepareStatement(sql);
pstat.setString(1, s.getUsername());
pstat.setString(2, s.getPassword());
pstat.setString(3, s.getEmail());
pstat.setInt(4, s.getAge());
pstat.setString(5, s.getClasses());
pstat.setString(6, s.getSex());
pstat.executeUpdate();
DBconnect.close(null, pstat, conn);
}
大家帮忙看看怎么回事。
------解决方案--------------------难道你用的是全角的问号?