• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Largest Row Number

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to write an SQL statement to get the Largest number out of an Access database table. I know it sounds simple but when I try "SELECT MAX (Question.qID) FROM Question"; this does not work, it says "Column Count not Found". If I run the query in Access then it works but I need to be able to get this number in JAVA so that I can then add one to it for a new id number. When I try just listing the id numbers in the table it works but when I add the MAX to the query I get an error. Thank you for your help!!
I have been trying something like:
private int getNewQID(){
int qID = 0;
String sql3 = "SELECT Max(Question.qID) FROM Question";
try{
rs = dataAccess.runSelectQuery(sql3);
while (rs.next()){
qID = (rs.getInt("qID"));
qID = qID +1;
System.out.println(qID);
}
}catch(Exception sqle) {
System.err.println("SQL NOT Executed: " + sqle);
}
return qID;
}
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The column name you are looking for probably idn't called qID. I don't know what name Access uses as a default for aggregate functions, but it's probably not something you want to code into your application. You have two options for solving the problem:
1) Explicitly name the column in your select statement. "SELECT MAX (Question.qID) as "qID" FROM Question"
2) Use the column number: rs.getInt(1);
reply
    Bookmark Topic Watch Topic
  • New Topic