File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve next resultset

 
Patrick Sor
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have three buttons with Retrieve, Next and Previous where it could selects the previous or next records. Lets say in my database there is three messages with messageid 1,2,3. I retrieve the first message by using resultset. And in order to retrieve the next message (using Next button) I store the messageid in a cookie. And subsequently increment the messageid to retieve it using SQL.
The problem is if messageid 2 is deleted, I can't retrieve the first message and next third message. What's the solution to this problem?

Here's the summary of my code



Please help. I have tried to find the solution for over a week. Thanks..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patrick,
In the following statement, what does SQLstr0 refer to?
 
Ali Gohar
Ranch Hand
Posts: 572
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try to explain your problem properly.
If you are retreiving messages using message id from the table like:
Select * from table where message_id=1
and any message id is deleted then it will create problem to retrieve next.
You can retrieve the records by using the for loop:
Your query will be "select * from table";
for(int i=1;rs.next();i++){
if(i==messageID){//here messageID is what you got from cookie and incremented
//It is the required record you want
//retrieve record and return
}
}
If this is not your problem then explain and try to send the whole code or otherwise comment to explain the code.
 
Patrick Sor
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll explain in more detail:
I have developed a J2ME messenger application where it used HTTP connection to connect to a server. And the database is MySQL being connected from the server.
When client (mobile phone) wanted to receive a message, it sends a command to server and the server response back by sending the message. Besides receive, I have two other buttons called previous and next where it selects next or previous message.
The message is stored in MySQL database and I have assigned an identification number to every message. In order to retrieve e.g. the next message, previous messageid is stored in cookie and just increments it.
Lets say there is two message with messageid 1, and 3. Right now when I press receive, server will reply by sending messageid 1 to client and messageid 1 is being stored in the cookie. When i pressed next there is no message available, because there is no messageid 2.
How do I solve it?
Here's my code:


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patrick,
I assume you update the message id in the session somewhere? Also, I assume you update the indexes that previous and next refer to?
The only other thing I can think of is to try using a nested query to get the first element (above a certain index) to compensate for one that is deleted.
 
Patrick Sor
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I did it. I retrieve resultset.getrow() and increments it. Adapting Ali Gohar 'for' loop with it.
Thanks for your help, Ali Gohar and Jeanne Boyarsky.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic