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)求高人指点迷津
{
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)求高人指点迷津
"select Id from Card where Password = '"+ Password + "'";
"select Password from Card where Id = '"+ name + "'";
"select Id from Card where Password = '"+ Password + "'";
在他后面增加一个输出语句System.out.println(sql);把输出的sql复制用数据库查询
(这条提示很重要,刚开始接触JDBC,感觉有点慌乱..........)