Here you can find the source of getLastCreatedEntry(Connection conn, String tableName)
public static int getLastCreatedEntry(Connection conn, String tableName) throws SQLException
//package com.java2s; //License from project: LGPL import java.sql.*; public class Main { public static int getLastCreatedEntry(Connection conn, String tableName) throws SQLException { int id = -1; String sql = "SELECT id FROM " + tableName + " ORDER BY id DESC LIMIT 1"; Statement st = conn.createStatement(); try {/*from ww w . ja v a2 s . c om*/ ResultSet resultSet = st.executeQuery(sql); if (resultSet.next()) { id = resultSet.getInt("id"); } else throw new SQLException("No results"); } finally { st.close(); } if (id >= 0) { return id; } else { throw new SQLException(); } } }