File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Retrieve next resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retrieve next resultset" Watch "Retrieve next resultset" New topic
Author

Retrieve next resultset

Patrick Sor
Greenhorn

Joined: Apr 17, 2004
Posts: 3
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Patrick,
In the following statement, what does SQLstr0 refer to?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
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

Joined: Apr 17, 2004
Posts: 3
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

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

Joined: Apr 17, 2004
Posts: 3
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.
 
Consider Paul's rocket mass heater.
 
subject: Retrieve next resultset
 
Similar Threads
Closing a db connection
Using a prepared statement
Efficent way to display HTML?
File encoding configuration in Tomcat
Fake a post request from java class