Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get records by database row number

 
Aaron Ahearne
Greenhorn
Posts: 2
Java jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aaron Ahearne
Greenhorn
Posts: 2
Java jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic