List of usage examples for java.sql ResultSet wasNull
boolean wasNull() throws SQLException;
NULL
. From source file:at.alladin.rmbt.db.fields.BooleanField.java
@Override public void setField(final ResultSet rs) throws SQLException { value = rs.getBoolean(dbKey);// ww w . j a v a2 s . c o m if (rs.wasNull()) value = null; }
From source file:at.alladin.rmbt.db.fields.IntField.java
@Override public void setField(final ResultSet rs) throws SQLException { value = rs.getInt(dbKey);// ww w. j av a 2 s . c o m if (rs.wasNull()) value = null; }
From source file:at.alladin.rmbt.db.fields.LongField.java
@Override public void setField(final ResultSet rs) throws SQLException { value = rs.getLong(dbKey);/*from w w w .java 2 s. co m*/ if (rs.wasNull()) value = null; }
From source file:at.alladin.rmbt.db.fields.DoubleField.java
@Override public void setField(final ResultSet rs) throws SQLException { value = rs.getDouble(dbKey);/*www . j a va 2 s . co m*/ if (rs.wasNull()) value = null; }
From source file:com.zimbra.cs.mailbox.util.MetadataDump.java
private static List<Row> getRevisionRows(DbConnection conn, int groupId, int mboxId, int itemId, boolean fromDumpster) throws ServiceException { PreparedStatement stmt = null; ResultSet rs = null; try {//from ww w . ja va 2 s .c o m String sql = "SELECT * FROM " + DbMailItem.getRevisionTableName(groupId, fromDumpster) + " WHERE mailbox_id = " + mboxId + " AND item_id = " + itemId + " ORDER BY mailbox_id, item_id, version DESC"; stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); List<Row> rows = new ArrayList<Row>(); while (rs.next()) { Row row = new Row(); ResultSetMetaData rsMeta = rs.getMetaData(); int cols = rsMeta.getColumnCount(); for (int i = 1; i <= cols; i++) { String colName = rsMeta.getColumnName(i); String colValue = rs.getString(i); if (rs.wasNull()) colValue = null; row.addColumn(colName, colValue); } rows.add(row); } return rows; } catch (SQLException e) { throw ServiceException.INVALID_REQUEST("No such item: mbox=" + mboxId + ", item=" + itemId, e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Execute an SQL statement and return the set of Long-objects * in its result set.//from www . java2s.c o m * * NB: the provided connection is not closed. * * @param connection connection to the database. * @param query the given sql-query (must not be null or empty string) * @param args The arguments to insert into this query * @return the set of Long-objects in its result set */ public static Set<Long> selectLongSet(Connection connection, String query, Object... args) { ArgumentNotValid.checkNotNull(connection, "Connection connection"); ArgumentNotValid.checkNotNullOrEmpty(query, "String query"); ArgumentNotValid.checkNotNull(args, "Object... args"); PreparedStatement s = null; try { s = prepareStatement(connection, query, args); ResultSet result = s.executeQuery(); Set<Long> results = new TreeSet<Long>(); while (result.next()) { if (result.getLong(1) == 0L && result.wasNull()) { String warning = "NULL value encountered in query: " + query; log.warn(warning); } results.add(result.getLong(1)); } return results; } catch (SQLException e) { throw new IOFailure("Error preparing SQL statement " + query + " args " + Arrays.toString(args) + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } finally { closeStatementIfOpen(s); } }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Execute an SQL statement and return the list of Long-objects * in its result set.//from w ww . java2 s. co m * * NB: the provided connection is not closed. * * @param connection connection to the database. * @param query the given sql-query (must not be null or empty string) * @param args The arguments to insert into this query * @return the list of Long-objects in its result set */ public static List<Long> selectLongList(Connection connection, String query, Object... args) { ArgumentNotValid.checkNotNull(connection, "Connection connection"); ArgumentNotValid.checkNotNullOrEmpty(query, "String query"); ArgumentNotValid.checkNotNull(args, "Object... args"); PreparedStatement s = null; try { s = prepareStatement(connection, query, args); ResultSet result = s.executeQuery(); List<Long> results = new ArrayList<Long>(); while (result.next()) { if (result.getLong(1) == 0L && result.wasNull()) { String warning = "NULL value encountered in query: " + query; log.warn(warning); } results.add(result.getLong(1)); } return results; } catch (SQLException e) { throw new IOFailure("Error preparing SQL statement " + query + " args " + Arrays.toString(args) + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } finally { closeStatementIfOpen(s); } }
From source file:com.act.lcms.db.model.ScanFile.java
protected static List<ScanFile> fromResultSet(ResultSet resultSet) throws SQLException { List<ScanFile> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); String filename = resultSet.getString(DB_FIELD.FILENAME.getOffset()); SCAN_MODE scanMode = SCAN_MODE.valueOf(resultSet.getString(DB_FIELD.MODE.getOffset())); SCAN_FILE_TYPE fileType = SCAN_FILE_TYPE.valueOf(resultSet.getString(DB_FIELD.FILE_TYPE.getOffset())); Integer plateId = resultSet.getInt(DB_FIELD.PLATE_ID.getOffset()); if (resultSet.wasNull()) { plateId = null;//from ww w. j av a2 s . c om } Integer plateRow = resultSet.getInt(DB_FIELD.PLATE_ROW.getOffset()); if (resultSet.wasNull()) { plateRow = null; } Integer plateColumn = resultSet.getInt(DB_FIELD.PLATE_COLUMN.getOffset()); if (resultSet.wasNull()) { plateColumn = null; } results.add(new ScanFile(id, filename, scanMode, fileType, plateId, plateRow, plateColumn)); } return results; }
From source file:net.sourceforge.vulcan.spring.jdbc.RequestUserQuery.java
@Override protected Object mapRow(ResultSet rs, int rowNumber) throws SQLException { final String value = rs.getString("requested_by"); if (rs.wasNull()) { return null; }// w ww . jav a 2 s . c o m final boolean isScheduler = rs.getBoolean("scheduled_build"); if (isScheduler) { schedulers.add(value); } else { users.add(value); } return value; }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** Execute an SQL statement and return the single long in the result set. * * @param s A prepared statement/*from www .j av a 2 s .com*/ * @return The long 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 long or null value */ public static Long selectLongValue(PreparedStatement s) { ArgumentNotValid.checkNotNull(s, "PreparedStatement s"); try { ResultSet res = s.executeQuery(); if (!res.next()) { throw new IOFailure("No results from " + s); } Long resultLong = res.getLong(1); if (res.wasNull()) { resultLong = null; } if (res.next()) { throw new IOFailure("Too many results from " + s); } return resultLong; } catch (SQLException e) { throw new IOFailure( "SQL error executing statement " + s + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } }