Here you can find the source of getNextId(Connection con, String table, String identityFieldName)
public static int getNextId(Connection con, String table, String identityFieldName) throws SQLException
//package com.java2s; /*//from ww w. j a va 2 s. c o m * codjo.net * * Common Apache License 2.0 */ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static int getNextId(Connection con, String table, String identityFieldName) throws SQLException { Statement stmt = con.createStatement(); try { ResultSet rs = stmt.executeQuery( "select max(" + identityFieldName + ") as " + identityFieldName + " from " + table); try { if (rs.next()) { return rs.getInt(1) + 1; } else { return 1; } } finally { rs.close(); } } finally { stmt.close(); } } }