1 Replies - 6546 Views - Last Post: 11 October 2007 - 08:32 PM Rate Topic: -----

#1 kensington   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 08-October 07

Max id from Database table

Posted 11 October 2007 - 06:18 PM

What is the best way to get the max id from a database table?

Here is how I am doing it now:

Resultset rs = statement.executeQuery("select max(id) from TableMain");
 rs.next();
 int myMaxId = rs.getInt(1);
 //my insert sql is here to insert into another table the value of the max id (myMaxId) ....

Is This A Good Question/Topic? 0
  • +

Replies To: Max id from Database table

#2 Liontrue1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 48
  • View blog
  • Posts: 811
  • Joined: 20-May 06

Re: Max id from Database table

Posted 11 October 2007 - 08:32 PM

View Postkensington, on 11 Oct, 2007 - 09:18 PM, said:

What is the best way to get the max id from a database table?

Here is how I am doing it now:

Resultset rs = statement.executeQuery("select max(id) from TableMain");
 rs.next();
 int myMaxId = rs.getInt(1);
 //my insert sql is here to insert into another table the value of the max id (myMaxId) ....


Hi there, it seems that the above code is correct Your myMaxId variable now contains the max id. Are you getting problems with that code?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1