奇怪问题,请高手指点,Illegal operation on empty result set.

lxkj123 2010-01-28 11:10:29
特别说明:该问题对一部分数据提示错误,对一部分数据则正常,非常奇怪
null
java.sql.SQLException: Illegal operation on empty result set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:815)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:552
8)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5448)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5488)
at net.sf.odinms.client.MaplePet.loadFromDb(MaplePet.java:46)
at net.sf.odinms.tools.MaplePacketCreator.addItemInfo(MaplePacketCreator
.java:1213)
at net.sf.odinms.tools.MaplePacketCreator.addItemInfo(MaplePacketCreator
.java:1144)
at net.sf.odinms.tools.MaplePacketCreator.getCharInfo(MaplePacketCreator
.java:866)
at net.sf.odinms.net.channel.handler.PlayerLoggedinHandler.handlePacket(
PlayerLoggedinHandler.java:94)
at net.sf.odinms.net.MapleServerHandler.messageReceived(MapleServerHandl
er.java:118)
at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messa
geReceived(AbstractIoFilterChain.java:570)
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageR
eceived(AbstractIoFilterChain.java:299)
at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(Abst
ractIoFilterChain.java:53)
at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.mess
ageReceived(AbstractIoFilterChain.java:648)
at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flus
h(SimpleProtocolDecoderOutput.java:58)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(Prot
ocolCodecFilter.java:180)
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageR
eceived(AbstractIoFilterChain.java:299)
at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(Abst
ractIoFilterChain.java:53)
at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.mess
ageReceived(AbstractIoFilterChain.java:648)
at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorF
ilter.java:220)
at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.
run(ExecutorFilter.java:264)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnabl
e.java:51)
at java.lang.Thread.run(Unknown Source)
...全文
695 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
bunrise 2010-01-28
  • 打赏
  • 举报
回复
if(rs.next());
{
ret.setName(rs.getString("name"));
ret.setCloseness(rs.getInt("closeness"));
ret.setLevel(rs.getInt("level"));
ret.setFullness(rs.getInt("fullness"));
} else{
return null;
}

return ret;
} catch (SQLException ex) {
Logger.getLogger(MaplePet.class.getName()).log(Level.SEVERE, null, ex);
return null;
}finnal{
rs.close();
ps.close();
}
focusforce 2010-01-28
  • 打赏
  • 举报
回复
rs.close(); 放到finally语句试试
lxkj123 2010-01-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 focusforce 的回复:]
if(rs.next())
            {
            ret.setName(rs.getString("name"));
            ret.setCloseness(rs.getInt("closeness"));
            ret.setLevel(rs.getInt("level"));
            ret.setFullness(rs.getInt("fullness"));
            }
重新运行试试,保证执行的是重新编译过的class。
[/Quote]

经反复测试,问题依旧,大家再看看还有什么问题?
focusforce 2010-01-28
  • 打赏
  • 举报
回复
if(rs.next())
{
ret.setName(rs.getString("name"));
ret.setCloseness(rs.getInt("closeness"));
ret.setLevel(rs.getInt("level"));
ret.setFullness(rs.getInt("fullness"));
}
重新运行试试,保证执行的是重新编译过的class。
bunrise 2010-01-28
  • 打赏
  • 举报
回复
SELECT * FROM pets WHERE petid = id
去数据库先查一查数据在说,你数据库没数据吧
lxkj123 2010-01-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lxd520123 的回复:]
if(rs.next()); //这里这么有个分号?


if(rs != null && rs.next()){}

[/Quote]

按如上修改后,还是提示一样的错误,真是奇怪了,大家看看还有什么可能?
bunrise 2010-01-28
  • 打赏
  • 举报
回复
if(rs.next()); //这里这么有个分号?


if(rs != null && rs.next()){}
gjgj3368 2010-01-28
  • 打赏
  • 举报
回复
//有可能rs为空
if(rs.next());
lxkj123 2010-01-28
  • 打赏
  • 举报
回复
源程序对应:
public static MaplePet loadFromDb(int itemid, byte position, int petid) {
try {
MaplePet ret = new MaplePet(itemid, position, petid);
Connection con = DatabaseConnection.getConnection(); // Get a connection to the database
PreparedStatement ps = con.prepareStatement("SELECT * FROM pets WHERE petid = ?"); // Get pet details..
ps.setInt(1, petid);
ResultSet rs = ps.executeQuery();
if(rs.next());
{
ret.setName(rs.getString("name"));
ret.setCloseness(rs.getInt("closeness"));
ret.setLevel(rs.getInt("level"));
ret.setFullness(rs.getInt("fullness"));
}
rs.close();
ps.close();
return ret;
} catch (SQLException ex) {
Logger.getLogger(MaplePet.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
zhuzhusany 2010-01-28
  • 打赏
  • 举报
回复
看Exception就知道,是对空数据集的操作是非法的
hp5212000 2010-01-28
  • 打赏
  • 举报
回复
Illegal operation on empty result set

你的数据集返回的是null值
1) 检查你的sql语句 是否正确
2) 确实无数据返回 要加异常处理
hp5212000 2010-01-28
  • 打赏
  • 举报
回复
"特别说明:该问题对一部分数据提示错误,对一部分数据则正常,非常奇怪 "
lz所说这个是什么意思?
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

62,610

社区成员

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

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