String strSQL = "select UserId form USER where Name='showjan'";  //------1
//String strSQL = "select UserID from USER";                     //------2
try{
    ResultSet sqlRst = db.executeQuery(strSQL);    if (sqlRst.next()){ .....
我用2时没任何问题问题,但用1时报“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 'USER where Name='showjan'' at line 1”的异常。我数据库为MySql5.1.
调度在MyEclipse
前提,数据库中有Name为showjan的纪录。
我对MySql不熟,是否有什么没配对?

解决方案 »

  1.   

    "select UserId form USER where Name='showjan'"
    你直接用的单引号还是全角的吧,转义一下
      

  2.   

    Name可能是关键字,用别的字段查询试试看
      

  3.   

    user是关键字,这个你自己使用 MySQL QUERY BROWER就知道了,能高亮显示。解决的方法就是 selece UserId from `USER` where name=''"
    注意,关键字要用反引号括起来,这个符号在键盘上的 TAB键上面,感叹号旁边。
      

  4.   

    有可能是Name是关键字,表名和字段名都最好不要是关键字,我以有一次试过,Sqlserver我建一个表名为user的表,然后执行select * from user就会有错