Here you can find the source of getId(ResultSet key)
Parameter | Description |
---|---|
key | resultSet with key |
Parameter | Description |
---|---|
SQLException | when operation fails |
public static Long getId(ResultSet key) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.ResultSet; import java.sql.SQLException; public class Main { /**/*from ww w . ja va 2 s. com*/ * Extract key from given ResultSet. * * @param key resultSet with key * @return key from given result set * @throws SQLException when operation fails */ public static Long getId(ResultSet key) throws SQLException { if (key.getMetaData().getColumnCount() != 1) { throw new IllegalArgumentException("Given ResultSet contains more columns"); } if (key.next()) { Long result = key.getLong(1); if (key.next()) { throw new IllegalArgumentException("Given ResultSet contains more rows"); } return result; } else { throw new IllegalArgumentException("Given ResultSet contain no rows"); } } }