get New Row generated Key from PreparedStatement - Java java.sql

Java examples for java.sql:PreparedStatement

Description

get New Row generated Key from PreparedStatement

Demo Code


//package com.java2s;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Main {
    public static int getNewRowKey(PreparedStatement statement)
            throws Exception {
        ResultSet rs = statement.getGeneratedKeys();
        if (rs.next()) {
            return rs.getInt(1);
        }/*from   w w  w  .java 2  s  .c o  m*/
        return -1;
    }
}

Related Tutorials