Welcome to Dream.In.Code
Become a Java Expert!

Join 149,594 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,865 people online right now. Registration is fast and FREE... Join Now!




Max id from Database table

 
Reply to this topicStart new topic

Max id from Database table

kensington
11 Oct, 2007 - 05:18 PM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 31


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

Here is how I am doing it now:

CODE

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) ....



User is offlineProfile CardPM
+Quote Post

alpha02
RE: Max Id From Database Table
11 Oct, 2007 - 07:32 PM
Post #2

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
QUOTE(kensington @ 11 Oct, 2007 - 09:18 PM) *

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

Here is how I am doing it now:

CODE

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?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:16PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month