List of usage examples for java.sql ResultSet wasNull
boolean wasNull() throws SQLException;
NULL
. From source file:com.thesett.util.hibernate.JsonUserType.java
/** {@inheritDoc} */ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { String content = rs.getString(names[0]); if (rs.wasNull()) { return null; }/*from ww w . jav a 2 s . c o m*/ return convertJsonToObject(content); }
From source file:com.itemanalysis.jmetrik.stats.irt.linking.DbThetaDistribution.java
public DistributionApproximation getDistribution(Connection conn, DataTableName tableName, VariableName thetaName, VariableName weightName, boolean hasWeight) throws SQLException { points = new ArrayList<Double>(); Min min = new Min(); Max max = new Max(); Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery query = new SelectQuery(); query.addColumn(sqlTable, thetaName.nameForDatabase()); if (hasWeight) { query.addColumn(sqlTable, weightName.nameForDatabase()); weights = new ArrayList<Double>(); }//from w ww .j a v a 2 s .co m Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(query.toString()); double value = 0.0; double w = 1.0; while (rs.next()) { value = rs.getDouble(thetaName.nameForDatabase()); if (!rs.wasNull()) { if (hasWeight) { w = rs.getDouble(weightName.nameForDatabase()); if (rs.wasNull()) { w = 0.0; } points.add(value); weights.add(w); min.increment(value); max.increment(value); } else { points.add(value); min.increment(value); max.increment(value); } } } rs.close(); stmt.close(); ContinuousDistributionApproximation dist = new ContinuousDistributionApproximation(points.size(), min.getResult(), max.getResult()); if (hasWeight) { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); dist.setDensityAt(i, weights.get(i)); } } else { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); } } return dist; }
From source file:net.sourceforge.vulcan.spring.jdbc.BuildQuery.java
private Object[] mapMessageArgs(ResultSet rs, String columnPrefix) throws SQLException { final List<String> args = new ArrayList<String>(); for (int i = 0; i < 4; i++) { final String arg = rs.getString(columnPrefix + i); if (rs.wasNull()) { break; }/*from w w w.j av a 2s. co m*/ args.add(arg); } if (args.isEmpty()) { return null; } return args.toArray(new String[args.size()]); }
From source file:net.solarnetwork.node.dao.jdbc.power.test.JdbcPowerDatumDaoTest.java
@Test public void storeNew() { PowerDatum datum = new PowerDatum(); datum.setCreated(new Date()); datum.setWatts(TEST_WATTS);//from w w w . j a v a2 s .com datum.setSourceId(TEST_SOURCE_ID); datum.setWattHourReading(TEST_WATT_HOURS); dao.storeDatum(datum); jdbcOps.query(SQL_GET_BY_ID, new Object[] { datum.getCreated(), datum.getSourceId() }, new ResultSetExtractor<Object>() { @Override public Object extractData(ResultSet rs) throws SQLException, DataAccessException { assertTrue("Must have one result", rs.next()); int col = 1; rs.getTimestamp(col++); assertFalse(rs.wasNull()); String s = rs.getString(col++); assertFalse(rs.wasNull()); assertEquals(TEST_SOURCE_ID, s); int w = rs.getInt(col++); assertFalse(rs.wasNull()); assertEquals(TEST_WATTS.intValue(), w); long wh = rs.getLong(col++); assertFalse(rs.wasNull()); assertEquals(TEST_WATT_HOURS.longValue(), wh); assertFalse("Must not have more than one result", rs.next()); return null; } }); }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** Returns the version of a table according to schemaversions, or 0 * for the initial, unnumbered version./*w w w .j av a2s . co m*/ * * NB: the provided connection is not closed * * @param connection connection to the database. * @param tablename The name of a table in the database. * @return Version of the given table. * @throws IOFailure if DB table schemaversions does not exist */ public static int getTableVersion(Connection connection, String tablename) throws IOFailure { ArgumentNotValid.checkNotNull(connection, "Connection connection"); ArgumentNotValid.checkNotNullOrEmpty(tablename, "String tablenname"); PreparedStatement s = null; int version = 0; try { s = connection.prepareStatement("SELECT version FROM schemaversions" + " WHERE tablename = ?"); s.setString(1, tablename); ResultSet res = s.executeQuery(); if (!res.next()) { log.warn("As yet unknown tablename '" + tablename + "' in table schemaversions. The table" + " should be automatically created in the database " + "when it is first needed."); } else { version = res.getInt(1); if (res.wasNull()) { log.warn("Null table version for '" + tablename + "'"); } } return version; } catch (SQLException e) { String msg = "SQL Error checking version of table " + tablename + "\n" + ExceptionUtils.getSQLExceptionCause(e); log.warn(msg, e); throw new IOFailure(msg, e); } finally { closeStatementIfOpen(s); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Integer getNullableInt32(ResultSet reader, int colidx) { try {//w w w .ja va 2s .c o m int val = reader.getInt(colidx); if (reader.wasNull()) { return (null); } else { return (new Integer(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstXMsgClientSchema.class, "getNullableInt32", e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Integer getNullableUInt16(ResultSet reader, int colidx) { try {// ww w .j ava 2s. com int val = reader.getInt(colidx); if (reader.wasNull()) { return (null); } else { return (new Integer(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstXMsgClientSchema.class, "getNullableUInt16", e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Long getNullableUInt32(ResultSet reader, int colidx) { try {//from w w w .j a v a 2 s . c o m long val = reader.getLong(colidx); if (reader.wasNull()) { return (null); } else { return (new Long(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstXMsgClientSchema.class, "getNullableUInt32", e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {/*from w w w . jav a2 s . c o m*/ byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstXMsgClientSchema.class, "getNullableByte", e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//from ww w. j a va 2 s . c om short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstXMsgClientSchema.class, "getNullableInt64", e); } }