Results 1 to 15 of 15
Thread: After End Of Result set error?
- 10-05-2011, 09:32 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
After End Of Result set error?
ok so i have a problem with a database connection here is the query and the error i get please help
Java Code:public String getonlineplayer(int mapid,int pid){ String returnstring =""; if(mapid>0 && pid!=0){ try{ pst = con.prepareStatement("select * from players where areaid='"+mapid+"' and online='1' and ID!='"+pid+"'"); rs = pst.executeQuery(); while(rs.next()){ if(rs!=null){ returnstring += "username="+rs.getString("uname")+ ",xpos="+rs.getInt("xpos")+",ypos="+rs.getInt("ypos")+",playerimage="+rs.getInt("playerimage")+"#"; }else{ break; } } }catch(Exception e){ e.printStackTrace(); } } return returnstring; }Java Code:java.sql.SQLException: After end of result set at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841) at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2674) at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2815) at Mysql.getonlineplayer(Mysql.java:95) at EchoServer$ClientServiceThread.run(EchoServer.java:173)
- 10-05-2011, 09:43 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: After End Of Result set error?
Which line is line #95 in your code?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-05-2011, 09:53 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
Re: After End Of Result set error?
ok so it is this "returnstring += "username="+rs.getString("uname") ... "
- 10-05-2011, 09:57 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: After End Of Result set error?
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-05-2011, 10:04 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
Re: After End Of Result set error?
ok i have altered some of the code in order of left to right
its giving me line 97 which is "String pimage = rs.getString("playerimage");"Java Code:public String getonlineplayer(int mapid,int pid){ String returnstring =""; if(mapid>0 && pid!=0){ try{ pst = con.prepareStatement("select * from players where areaid='"+mapid+"' and online='1' and ID!='"+pid+"'",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs = pst.executeQuery(); if(rs.next()){ do{ if(rs!=null){ String uname = rs.getString("uname"); String pimage = rs.getString("playerimage"); String xpos = rs.getString("xpos"); String ypos = rs.getString("ypos"); returnstring += "username="+uname+ ",xpos="+xpos+",ypos="+ypos+",playerimage="+pimage+"#"; }else{ break; } }while(rs.next()); } }catch(Exception e){ e.printStackTrace(); } } return returnstring; }
- 10-06-2011, 08:11 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 10-06-2011, 09:07 AM #7
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Re: After End Of Result set error?
before while loop, try to put rs.beforeFirst().
Also remove the if condition before you do while loop because you are skipping one record by doing that.
- 10-06-2011, 09:24 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: After End Of Result set error?
The beforeFirst() call should't be needed; from the API documentation of the next() method:
The first call to next() positions the ResultSet at the first row (if any).Moves the cursor froward one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-06-2011, 01:26 PM #9
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
Re: After End Of Result set error?
ok i have done all the changes you said but nothing still error forgot to say that the function is in a thread which is contanstly calling the method if that help? here is code
Java Code:public String getonlineplayer(int mapid,int pid){ String returnstring =""; if(mapid>0 && pid!=0){ try{ pst = con.prepareStatement("select * from players where areaid='"+mapid+"' and online='1' and ID!='"+pid+"'",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs = pst.executeQuery(); rs.beforeFirst(); while(rs.next()){ String uname = rs.getString("uname"); int pimage = rs.getInt("playerimage"); int xpos = rs.getInt("xpos"); int ypos = rs.getInt("ypos"); returnstring += "username="+uname+ ",xpos="+Integer.toString(xpos)+",ypos="+Integer.toString(ypos)+",playerimage="+Integer.toString(pimage)+"#"; } }catch(Exception e){ e.printStackTrace(); System.out.println("["+pid+"]Online Players Error While Validating "+e); } } return returnstring; }
- 10-06-2011, 01:43 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 10-06-2011, 02:08 PM #11
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
- 10-06-2011, 02:30 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 10-07-2011, 12:07 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: After End Of Result set error?
Since this is multi-threaded I hope that your statment and resultset objects are local to this method.
Since it is clear they are not I would suggest you change that, as that is the cause (almost certainly) of your problem.
Synchronising this method will only be a sticky-tape fix, as you'll use up your db cursors before too long.
- 10-07-2011, 07:14 PM #14
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
Re: After End Of Result set error?
Ok got it sorted did what u said about the synchronized method and it has solved my problems thanks all! :)
- 10-09-2011, 05:03 PM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Similar Threads
-
Keep getting result of 0.
By dookie1293 in forum New To JavaReplies: 7Last Post: 06-09-2011, 05:01 AM -
Struts 2 error : No result defined for action / result
By sameerk in forum Web FrameworksReplies: 1Last Post: 05-17-2011, 10:15 AM -
uncorrect result
By jamborta in forum New To JavaReplies: 3Last Post: 11-11-2009, 01:17 PM -
Google Error - "This site may harm your computer" on every search result?!?!
By angryboy in forum Forum LobbyReplies: 2Last Post: 03-18-2009, 08:36 PM -
getting a random result
By gradon in forum New To JavaReplies: 2Last Post: 07-19-2007, 03:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks