Code example for Statement

Methods: executeUpdate, getGeneratedKeys

0
	 *             If for some reason the query fails. 
	 */ 
	public int insertAndReturnLastInsertedID(String insertQuery)
			throws SQLException { 
		Statement st = databaseConnection.createStatement();
		st.executeUpdate(insertQuery, Statement.RETURN_GENERATED_KEYS);
		ResultSet rs = st.getGeneratedKeys();
 
		int id = -1;
		if (rs.next()) {
			id = rs.getInt(1);
		} else { 
			throw new SQLException("Unable to retrieve last inserted id.");
		} 
		rs.close();
		rs = null;
		return id;
	} 
 
	/** 
	 * This method executes a delete query on the database to which this object