>> I have a repeated resultset object that I use alot to execute a
>> statement that fetches max id from a table.
[quoted text clipped - 6 lines]
>> TableMain");
>> rs.next();
I know I have mentioned repeatedly in answer to this question as you have
reposted it, and others have too, that you absolutely must check the return
value of rs.next().
If you don't value our advice, why do you request it?

Signature
Lew
ram00540@gmail.com - 15 Oct 2007 12:33 GMT
> Arne Vajh?j wrote:
> > tes...@hotmail.com wrote:
[quoted text clipped - 17 lines]
> --
> Lew
hi you can create the function is as below.
public static int getMax(String column, String table) {
PreparedStatement st = null;
ResultSet rs = null;
Connection con = null;
int maxid = 0;
try {
con = DatabaseUtil.getConnection();
String query = "select max(" + column + ") from " + table + ";";
st = con.prepareStatement(query);
rs = st.executeQuery();
while (rs != null && rs.next()) {
maxid = rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (st != null)
st.close();
if (con != null)
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return maxid;
}
}
and call every time you have required.