道兄,帮我看看这验证用户名字是否相同的问题

gentoo 02-10-21


这是一个bean ,验证名字是否存在
public boolean queryName()
{
try
{
if(this.isValid())
{

String sql = "select * from '"+tableName+"' where '"+columName+"'= ?";
Mysql mysql = new Mysql(sql);
mysql.setString(1,
"name");
rs = mysql.executeQuery();
if(rs.next())
{
String tempName = rs.getString(
"Username");
if(tempName==null && tempName.equals(
"")) valid = false;
}

}
}
catch(Exception e)
{
System.out.println(e);
}
return valid;
}
}
这是我写的jsp调用上面那个bean
<jsp:useBean id=
"IsParity" class="weixiu.IsParity" />
<%

String username = null; username = request.getParameter(
"username");
IsParity.setName(
"username");
IsParity.setTable(
"login");
IsParity.setColum(
"Username");

if(IsParity.queryName())
{
out.println(
"Sorry!");
}
else
{
out.println(
"go....");
}

%>

但是不管结果是什么,就算数据库中没有这个名字它只显示sorry,请问什么原因呢?

why10k
2002-10-23 16:33

Now i have nothing to do :)
try it:
if(tempName==null && tempName.equals("")) valid = false;
--->if(tempName==null || tempName.equals("")) valid = false;