I am using the following code to get the last record of a table but i face one problem



try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:OnlineElect ricals");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("select Item_ID from Item_Details");
if(!rs.next())
{
Item_ID = "IT0001";

}
else
{
rs = stat.executeQuery("select Item_Id from Item_Details");
rs.last();
Item_ID = rs.getString("Item_ID");
String Item = Item_ID.substring(0,1);
String ID = Item_ID.substring(2);
ID = ID + 1;
Item_ID = Item + ID;
}

rs.close();
stat.close();
con.close();

}
catch(Exception e)
{
System.out.println(e);
}


Actually by this coding i want to increase the value of Item_ID field automatically when save button is pressed.

Remember that the type of Item_ID field is varchar(SQL Server)

i get one solution from forums but it is not working it is below

Query : select Item_ID from Item_Details where Item_ID=(select MAX(Item_ID) from Item_Details)

This is not working because the type of Item_ID field is varchar(10)