Code example for Statement

Methods: close, executeQuery, executeUpdate

0
 
		try { 
 
			String selectQuery = String.format("SELECT id FROM %s",
					sequence_table);
			ResultSet resultSet = statement.executeQuery(selectQuery);
 
			long lastID;
			if (resultSet.first()) {
 
				lastID = resultSet.getLong("id");
				lastID++;
 
				statement.executeUpdate(String.format("UPDATE %s SET id=%d",
						sequence_table, lastID));
 
			} else { 
				throw new SQLException(sequence_table
						+ " didn't return a new id"); 
			} 
 
			connection.commit();
 
			return Long.toString(lastID);
 
		} catch (SQLException e) {
			logger.warn("Exception getting next id from " + sequence_table
					+ " - " + e.getMessage(), e);
			throw e;
		} finally { 
			try { 
				statement.close();
			} catch (SQLException e) {
				logger.warn("Exception closing statement - " + e.getMessage()
						+ " - IGNORING"); 
			} 
			try {