package org.a6v.mecha.db.mysql;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcUtil {
    /**
     * Return the first generated key in the provided statement as an integer, or, <code>null</code> if the statement
     * does not contain generated keys.
     *
     * @since mk14 mod0 (CRYSTAL)
     */
    public static Integer getFirstGeneratedKey(Statement st) throws SQLException {
        ResultSet generatedKeys = st.getGeneratedKeys();
        if (generatedKeys.next()) {
            return generatedKeys.getInt(1);
        }
        return null;
    }
}
