public Boolean isHasInDB ( String name , String password )
    {
        Connection con = connetionDB.getConnetionDB ();
        Statement controlDB = null;
        //String SQL = "select Password from Card where Id = "+ name;//为什么这样就会出错??????????
        String SQL = "select Id from Card where Password = " + password;
        try
        {
            controlDB = con.createStatement ();
            ResultSet rsDB = controlDB.executeQuery ( SQL );
            while ( rsDB.next () )
            {                //if ( rsDB.getString ( 1 ).equals ( password ) )//为什么这样就会出错??????????
                if ( rsDB.getString ( 1 ).equals ( name ) )
                {
                    rsDB.close ();
                    con.close ();
                    controlDB.close ();
                    return true;
                }
            }
            rsDB.close ();
            con.close ();
            controlDB.close ();        }
        catch ( SQLException ex )
        {
            //return false;
            ex.printStackTrace ();
        }
        return false;
    }真的非常奇怪
按密码来查找就没问题按名字来查找的话就说没有这列...........我的名字和密码在SQL里的数据类型是carchar(50)求高人指点迷津

解决方案 »

  1.   

    应该都会出错的 "select Password from Card where Id = '"+ name + "'";
     "select Id from Card where Password = '"+ Password + "'";
      

  2.   

    net_lover(【孟子E章】)  : 早,,,我早起是被逼的,你呢?
      

  3.   

    //String SQL = "select Password from Card where Id = "+ name;//为什么这样就会出错??????????varchar 型 要加单引号,按密码查询不出错有可能数据库中密码的类型不是varchar,仔细检查一下
    "select Password from Card where Id = '"+ name + "'";
     "select Id from Card where Password = '"+ Password + "'";
    在他后面增加一个输出语句System.out.println(sql);把输出的sql复制用数据库查询
      

  4.   

    楼上的正解,如果值是数字,是varchar也不需要单引号不过最好还是都单引的好点谢谢咯 把输出的sql复制用数据库查询
    (这条提示很重要,刚开始接触JDBC,感觉有点慌乱..........)