aspose file tools*
The moose likes JDBC and the fly likes Get records by database row number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get records by database row number" Watch "Get records by database row number" New topic
Author

Get records by database row number

Aaron Ahearne
Greenhorn

Joined: Jan 06, 2011
Posts: 2

Hi, this is my first post!

I want to use SQL to select a record by its row number.

For example:
"SELECT * FROM dvdTable WHERE ROW_NUMBER = 1";

The reason being that a GUI displays a next button and gets a file path stored in the database. File path is used to create an image icon (using code I found here actually )
My method basically looks something like this:

dvd ++;
String filePath = methods.getNextFilePath(dvd);

ImageIcon image = new ImageIcon(filePath);
imageLbl.setIcon(image);


SO... where there have been deleted records and there are gaps between the primary keys, the database is returning nothing as there is no record where the dvd integer is being passed into the method.

I've looked everywhere and Im starting to think this method doesnt exist!

I have tried lots of different loops to try doing the method again if null is returned but nothing seems to work.

Any help appreciated
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

where there have been deleted records and there are gaps between the primary keys, the database is returning nothing as there is no record where the dvd integer is being passed into the method.

There are gaps ? How could there be gaps ?


[My Blog]
All roads lead to JavaRanch
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Aaron,
Welcome to CodeRanch!

Why not use a query to find the next valid id? Note that it is better to query by primary key rather than by row number.


[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
Aaron Ahearne
Greenhorn

Joined: Jan 06, 2011
Posts: 2

Christophe Verré wrote:
where there have been deleted records and there are gaps between the primary keys, the database is returning nothing as there is no record where the dvd integer is being passed into the method.

There are gaps ? How could there be gaps ?


There are gaps because when the method sets the dvd number to say 3 and the record with a primary key 3 has been deleted, because of auto increment there is no record to return.

The next record to return would maybe be 14, but you have to keep pressing the next button until int dvd reaches 14 you see?

Anyway I figured out a way to do it. I just used a constructor and an ArrayList to return a set of results. That way I will be cycling through using only the primary keys that exist and not one that I have tried to enter myself
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get records by database row number
 
Similar Threads
putting image files to Jar File in Swing application
Max. Denny's DVD Project: DVDDatabase class doubt
Extending Data class or not
Synchronization in the SCJD Exam with J2SE book
series of updates