Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

ResultSet Problem

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;";
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic