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);
}大家帮忙看看怎么回事。
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);
}大家帮忙看看怎么回事。
请教一下这是什么意思,是在www.sun.com注册时碰到的
rs=pstat.executeQuery(sql);
你已经把pstate实例化完成了,就不要再把sql当参数用了,直接
rs=pstat.executeQuery();
就OK了。