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);
 
 }大家帮忙看看怎么回事。

解决方案 »

  1.   

    Address must consist of western European characters, as defined in the ISO-8859-1 character set. 
     请教一下这是什么意思,是在www.sun.com注册时碰到的
      

  2.   

    说说如何解决的好吗,我也遇到这样子的问题mysql PreparedStatement联到网上的服务器上插入不了数据,但在本机运行一切正常,为什么,mysql都是5.0版本的呀?
      

  3.   

    我也刚碰到这个问题,自己解决了:
    rs=pstat.executeQuery(sql); 
    你已经把pstate实例化完成了,就不要再把sql当参数用了,直接
    rs=pstat.executeQuery();
    就OK了。