mysql illegal operation on empty result set 错误。在线急等

walkman_22 2011-08-19 06:00:21
关键代码如下:

public boolean matchNamePwd(User u){
if(u == null) {
return false;
}
String name = u.getName();
String pwd = u.getPwd();

String nameSql = "select id from user where name=?";
String pwdSql = "select id from login where pwd=?";

try {
conn = JdbcUtils.getConn();
pstmt = conn.prepareStatement(nameSql);
pstmt.setString(1, name);
rs = pstmt.executeQuery();
rs.next();
int idByName = rs.getInt(1);
System.out.println("idByName = " + idByName);

pstmt = conn.prepareStatement(pwdSql);
pstmt.setString(1, pwd);
rs = pstmt.executeQuery();
rs.next();

int idByPwd = rs.getInt(1);
System.out.println("idByPwd = " + idByPwd);
if(idByName == idByPwd) {
return true;
}else {
System.out.println("用户名 / 密码不匹配");
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}

return false;
}


大家看看有什么问题。急等。
...全文
718 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
whatstudio 2011-12-20
  • 打赏
  • 举报
回复
小问题,大麻烦
walkman_22 2011-08-22
  • 打赏
  • 举报
回复
问题已解决。送分。
安心逍遥 2011-08-20
  • 打赏
  • 举报
回复
你的查询没有值时int idByPwd = rs.getInt(1);
出错
int idByPwd = 0;
if(rs.next()){
idByPwd = rs.getInt(1);
}
Jeelon 2011-08-20
  • 打赏
  • 举报
回复
结果集为空!请LZ判断传进来的值是否为空 或者数据库是否有值?debug下吧?
caixuanbin 2011-08-20
  • 打赏
  • 举报
回复
也帮楼主顶顶
LMAOhuaNL 2011-08-20
  • 打赏
  • 举报
回复
int idByPwd = 0;
if(rs.next()){
idByPwd = rs.getInt(1);
}
一般都必须判断是否为空的,这个是必须要的
亲努力啊 2011-08-19
  • 打赏
  • 举报
回复
int idByPwd = 0;
if(rs.next()){
idByPwd = rs.getInt(1);
}
亲努力啊 2011-08-19
  • 打赏
  • 举报
回复
你的查询没有值时int idByPwd = rs.getInt(1);
出错
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver

81,087

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧