File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes get max(id) from table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "get max(id) from table" Watch "get max(id) from table" New topic

get max(id) from table

prriya pratheep

Joined: Jun 10, 2008
Posts: 22
Hi friends

In my program i am getting max(ID) an interger value from the resultset.I don't know how to convert that into integer.

String s3 = "select MAX(ID) from SALES_EMPLOYEE_MASTER";
ResultSet resultset = statement.executeQuery(s3);

If I use int maxid=resulltset.getInt(1); , I ma getting error.Please help me to how to retrieve a interger value from the resultset..

Thanks in advance
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
I had a similar problem last week, which turned out to be caused by not calling the next() method on my ResultSet object. Remember a ResultSet defaults to cursor on line "0" so you have to call next() (or first() or absolute(1) or similar) to get to a result at all.

If that doesn't help, please post some more code.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Or tell us what the error is. Details are always helpful, whereas vague statements like "I got an error" are not.
I agree. Here's the link:
subject: get max(id) from table
It's not a secret anymore!