为什么加上这一句就出现异常?请高手看看!

jndingxin 2004-11-03 09:45:20
<%
String name = sqlbean.toByteString(request.getParameter("name"));
String password = sqlbean.toByteString(request.getParameter("password"));
String username = sqlbean.toByteString(request.getParameter("username"));
String question = sqlbean.toByteString(request.getParameter("question"));
String answer = sqlbean.toByteString(request.getParameter("answer"));
String email = sqlbean.toByteString(request.getParameter("email"));
String mobile = sqlbean.toByteString(request.getParameter("mobile"));
String tel = sqlbean.toByteString(request.getParameter("tel"));
String depart = sqlbean.toByteString(request.getParameter("company"));
String ip = request.getRemoteAddr();
String pagesize = request.getParameter("pagesize");
String sex =sqlbean.toByteString(request.getParameter("sex"));
String Address =sqlbean.toByteString(request.getParameter("Address"));
String marriage =sqlbean.toByteString(request.getParameter("marriage"));

String sql = "select * from Usr where username='"+ username +"' or name='"+ name +"'";
sqlbean.executeQuery(sql);
if(sqlbean.next())//为什么加上这一句后就出现异常
{
out.println(。。。。。);//内容省略
}
else
{
}
去掉if(sqlbean.next())后,就正常输出,错误如下:
java.lang.NullPointerException
我测试了几次,发现错误就在if(sqlbean.next())这一句,
请高手指点,这一句改咋写?
...全文
91 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wandou999 2004-11-04
只有ResultSet才可以这样写,
ResultSet rs=sqlbean.executeQuery(sql);
while(rs.next())
{...}
回复
aoleiaolei 2004-11-04
ResultSet rs = sqlbean.executeQuery(sql.toString());
if (rs.next()){
}
必须生成ResultSet du对象
回复
aspgreener 2004-11-04
回复人: trumplet(检查) ( ) 信誉:99 2004-11-03 21:59:00 得分: 0


sqlbean是啥类型的?从代码看,应该是Statement。

Statement有next()方法吗?


Top

回复人: Net8Java(杜杜) ( ) 信誉:100 2004-11-04 02:46:00 得分: 0


rs=sqlbean.executeQuery(sql);
if(rs.next()){
out.println(.......);
}
else{
}





Top

回复人: wangwei8117(Jack_David) ( ) 信誉:100 2004-11-04 08:26:00 得分: 0


sqlbean.executeQuery(sql)是有返回值的啊!应该ResultSet rs=sqlbean.executeQuery(sql);
rs.next();
sqlbean不是记录集,怎么会有next()方法呢!


回复
wangwei8117 2004-11-04
sqlbean.executeQuery(sql)是有返回值的啊!应该ResultSet rs=sqlbean.executeQuery(sql);
rs.next();
sqlbean不是记录集,怎么会有next()方法呢!
回复
Net8Java 2004-11-04
rs=sqlbean.executeQuery(sql);
if(rs.next()){
out.println(.......);
}
else{
}


回复
trumplet 2004-11-03
sqlbean是啥类型的?从代码看,应该是Statement。

Statement有next()方法吗?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-11-03 09:45
社区公告
暂无公告