List of usage examples for java.sql ResultSet wasNull
boolean wasNull() throws SQLException;
NULL
. From source file:dk.netarkivet.common.utils.DBUtils.java
/** Execute an SQL statement and return the single integer * in the result set.//from w w w. j av a 2 s . c o m * * @param s A prepared statement * @return The integer result, or null if the result value was null. * @throws IOFailure if the statement didn't result in exactly one integer. */ public static Integer selectIntValue(PreparedStatement s) { ArgumentNotValid.checkNotNull(s, "PreparedStatement s"); try { ResultSet res = s.executeQuery(); if (!res.next()) { throw new IOFailure("No results from " + s); } Integer resultInt = res.getInt(1); if (res.wasNull()) { resultInt = null; } if (res.next()) { throw new IOFailure("Too many results from " + s); } return resultInt; } catch (SQLException e) { throw new IOFailure( "SQL error executing statement " + s + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** Execute an SQL statement and return the single string in the result set. * * @param s A prepared statement/*from w w w . j a v a 2 s .co m*/ * @return The string result, or null if the result was a null value * Note that a null value is not the same as no result rows. * @throws IOFailure if the statement didn't result in exactly one row with * a string or null value */ public static String selectStringValue(PreparedStatement s) { ArgumentNotValid.checkNotNull(s, "PreparedStatement s"); try { ResultSet res = s.executeQuery(); if (!res.next()) { throw new IOFailure("No results from " + s); } String resultString = res.getString(1); if (res.wasNull()) { resultString = null; } if (res.next()) { throw new IOFailure("Too many results from " + s); } return resultString; } catch (SQLException e) { throw new IOFailure( "SQL error executing statement " + s + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } }
From source file:com.act.lcms.db.model.Plate.java
protected static List<Plate> platesFromResultSet(ResultSet resultSet) throws SQLException { List<Plate> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); String name = resultSet.getString(DB_FIELD.NAME.getOffset()); String description = resultSet.getString(DB_FIELD.DESCRIPTION.getOffset()); String barcode = resultSet.getString(DB_FIELD.BARCODE.getOffset()); String location = resultSet.getString(DB_FIELD.LOCATION.getOffset()); String plateType = resultSet.getString(DB_FIELD.PLATE_TYPE.getOffset()); String solvent = resultSet.getString(DB_FIELD.SOLVENT.getOffset()); Integer temperature = resultSet.getInt(DB_FIELD.TEMPERATURE.getOffset()); if (resultSet.wasNull()) { temperature = null;//from w w w.j ava 2 s . com } CONTENT_TYPE contentType = CONTENT_TYPE.valueOf(resultSet.getString(DB_FIELD.CONTENT_TYPE.getOffset())); results.add(new Plate(id, name, description, barcode, location, plateType, solvent, temperature, contentType)); } return results; }
From source file:ru.org.linux.spring.dao.DeleteInfoDao.java
/** * , ?/*from ww w . j a v a2 s. com*/ * @param id id ? ?? * @param forUpdate ? (SELECT ... FOR UPDATE) * @return ? ? */ public DeleteInfo getDeleteInfo(int id, boolean forUpdate) { List<DeleteInfo> list = jdbcTemplate.query(forUpdate ? QUERY_DELETE_INFO_FOR_UPDATE : QUERY_DELETE_INFO, new RowMapper<DeleteInfo>() { @Override public DeleteInfo mapRow(ResultSet resultSet, int i) throws SQLException { Integer bonus = resultSet.getInt("bonus"); if (resultSet.wasNull()) { bonus = null; } return new DeleteInfo(resultSet.getInt("userid"), resultSet.getString("reason"), resultSet.getTimestamp("deldate"), bonus); } }, id); if (list.isEmpty()) { return null; } else { return list.get(0); } }
From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java
protected Integer getInteger(final ResultSet rs, final int columnIndex) throws SQLException { int result = rs.getInt(columnIndex); return rs.wasNull() ? null : result; }
From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java
protected Long getLong(final ResultSet rs, final int columnIndex) throws SQLException { long result = rs.getLong(columnIndex); return rs.wasNull() ? null : result; }
From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java
protected Integer getInteger(final ResultSet rs, final String columnLabel) throws SQLException { int result = rs.getInt(columnLabel); return rs.wasNull() ? null : result; }
From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java
protected Float getFloat(final ResultSet rs, final int columnIndex) throws SQLException { float result = rs.getFloat(columnIndex); return rs.wasNull() ? null : result; }
From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java
protected Long getLong(final ResultSet rs, final String columnLabel) throws SQLException { long result = rs.getLong(columnLabel); return rs.wasNull() ? null : result; }
From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java
protected Double getDouble(final ResultSet rs, final int columnIndex) throws SQLException { double result = rs.getDouble(columnIndex); return rs.wasNull() ? null : result; }