• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet Problem

 
Allen Thomas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am pulling my hair with such great frustration with this problem I having and I hope someone here could shed some light upon me.
I am using jdbc-odbc bridge connecting to an access database. In this database, I have a table which has to fields, id and pid. I don't have a primary key, which is probably our problem, but nonetheless...problem should not exist.
Anyways... the values I have in there are:
id pid equipment
12128 10859
12128 10859 screwdriver

this is my query...
selectQry = "SELECT id, pid FROM MasterMapping WHERE (pid IS NOT NULL) AND (equipment IS NOT NULL) ORDER BY id;";
ResultSet rst = db.queryData(selectQry);
if (rst != null){
while(rst.next()){
int IdKey = rst.getInt("id");
int pid = rst.getInt("pid");
System.out.println("ID: " + IdKey + " PID: " + pid);
}
rst.close();
}
...
...
I am expecting the output:
ID: 12128 PID: 10859
but I get this:
ID: 12128 PID: 10860
The PID increased by one. I have no idea anymore how I could get what is in the database which is the PID 10859
Any help is appreciated. Thank you in advance.
Allen
 
Pavel Halas
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks strange... Try using
String str = rs.getString("pid");
Let it write on terminal and then parse it using
int pid = Integer.parseInt(str);
May help you. No other solutions for now.
 
Braj Prasad
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems the first row entry in the database for the equipment field is not null, but an empty string instead. Try modifying the query to look for
selectQry = "SELECT id, pid FROM MasterMapping WHERE (pid IS NOT NULL) AND (equipment IS NOT NULL or equipment != '') ORDER BY id;";
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic