List of usage examples for java.sql ResultSet wasNull
boolean wasNull() throws SQLException;
NULL
. From source file:data.DefaultExchanger.java
protected void putLong(JsonGenerator generator, String fieldName, ResultSet rs, short index) throws SQLException, IOException { generator.writeFieldName(fieldName); long value = rs.getLong(index); if (rs.wasNull()) { generator.writeNull();//from ww w .j av a 2 s . c om } else { generator.writeNumber(value); } }
From source file:com.splicemachine.derby.impl.sql.execute.operations.CallStatementOperationIT.java
@Test public void testCallSqlColumns() throws Exception { int count = 0; DatabaseMetaData dmd = methodWatcher.getOrCreateConnection().getMetaData(); ResultSet rs = dmd.getColumns(null, "SYS", "SYSSCHEMAS", null); Set<String> correctNames = Sets.newHashSet("SCHEMAID", "SCHEMANAME", "AUTHORIZATIONID"); while (rs.next()) { String sIdCol = rs.getString(4); int colType = rs.getInt(5); Assert.assertTrue("No colType returned!", !rs.wasNull()); int colNum = rs.getInt(17); Assert.assertTrue("No colNum returned!", !rs.wasNull()); Assert.assertTrue("Incorrect column name returned!", correctNames.contains(sIdCol.toUpperCase())); count++;//from ww w. j a v a 2 s .com } Assert.assertEquals("incorrect rows returned!", 3, count); DbUtils.closeQuietly(rs); }
From source file:com.xqdev.sql.MLSQL.java
private static void addResultSet(Element root, ResultSet rs) throws SQLException { Namespace sql = root.getNamespace(); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); while (rs.next()) { Element tuple = new Element("tuple", sql); for (int i = 1; i <= columnCount; i++) { String colName = rsmd.getColumnName(i); // names aren't guaranteed OK in xml String colTypeName = rsmd.getColumnTypeName(i); // Decode a BLOB if one is found and place it into the result as a encoded Base 64 string String colValue = ""; if ("BLOB".equalsIgnoreCase(colTypeName)) { Blob b = rs.getBlob(i); if (b != null && b.length() > 0) { Base64 b64 = new Base64(); String b64Blob = b64.encodeBase64String(b.getBytes(1, (int) b.length())); colValue = b64Blob; } else colValue = ""; } else { colValue = rs.getString(i); }// w w w .j a v a 2s .c o m boolean wasNull = rs.wasNull(); Element elt = new Element(colName); if (wasNull) { elt.setAttribute("null", "true"); } if ("UNKNOWN".equalsIgnoreCase(colTypeName)) { tuple.addContent(elt.setText("UNKNOWN TYPE")); // XXX ugly } else { tuple.addContent(elt.setText(colValue)); } } root.addContent(tuple); } }
From source file:com.flexive.core.storage.MySQL.MySQLSequencerStorage.java
/** * {@inheritDoc}//from ww w .j av a 2s. co m */ @Override public long fetchId(String name, boolean allowRollover) throws FxCreateException { Connection con = null; PreparedStatement ps = null; try { // Obtain a database connection con = Database.getDbConnection(); // Prepare the new id ps = con.prepareStatement(SQL_NEXT); ps.setString(1, name); ps.executeUpdate(); if (ps.getUpdateCount() == 0) throw new FxCreateException(LOG, "ex.sequencer.typeUnknown", name); ps.close(); // Get the new id ps = con.prepareStatement(SQL_GETID); ResultSet rs = ps.executeQuery(); long newId; if (rs == null || !rs.next()) throw new FxCreateException(LOG, "ex.sequencer.fetch.failed", name); newId = rs.getLong(1); if (rs.wasNull()) throw new FxCreateException(LOG, "ex.sequencer.fetch.failed", name); if (newId >= MAX_ID) { if (!name.startsWith("SYS_")) { //get allowRollover setting ps.close(); ps = con.prepareStatement(SQL_GET_ROLLOVER); ps.setString(1, name); ResultSet rso = ps.executeQuery(); if (rso == null || !rso.next()) throw new FxCreateException(LOG, "ex.sequencer.fetch.failed", name); allowRollover = rso.getBoolean(1); } if (!allowRollover) throw new FxCreateException("ex.sequencer.exhausted", name); ps.close(); ps = con.prepareStatement(SQL_RESET); ps.setString(1, name); ps.executeUpdate(); if (ps.getUpdateCount() == 0) throw new FxCreateException(LOG, "ex.sequencer.typeUnknown", name); newId = 0; } // Return new id return newId; } catch (SQLException exc) { throw new FxCreateException(LOG, exc, "ex.sequencer.fetch.failedMsg", name, exc.getMessage()); } finally { Database.closeObjects(MySQLSequencerStorage.class, con, ps); } }
From source file:com.splicemachine.derby.impl.sql.execute.operations.InsertOperationIT.java
@Test public void testInsertOverMergeSortOuterJoinIsCorrect() throws Exception { /*//from w ww .ja va 2 s. c o m * Regression test for DB-1833. Tests that we can insert over a subselect that has a merge-sort * join present,without getting any errors. */ long insertCount = methodWatcher.executeUpdate(String.format("insert into %1$s select " + "%2$s.a,%3$s.c,%2$s.b,%3$s.d " + "from %2$s --SPLICE-PROPERTIES joinStrategy=SORTMERGE \n" + "right join %3$s on %2$s.a=%3$s.c", "T5", "T3", "T4")); Assert.assertEquals("Incorrect number of rows inserted!", 2, insertCount); ResultSet rs = methodWatcher.executeQuery("select * from T5"); int count = 0; while (rs.next()) { int a = rs.getInt(1); if (rs.wasNull()) { BigDecimal b = rs.getBigDecimal(3); Assert.assertTrue("B is not null!", rs.wasNull()); } else { BigDecimal b = rs.getBigDecimal(3); Assert.assertFalse("B is null!", rs.wasNull()); Assert.assertTrue("Incorrect B value!", BigDecimal.ONE.subtract(b).abs().compareTo(new BigDecimal(".0000000001")) < 0); } count++; int c = rs.getInt(2); Assert.assertFalse("C is null!", rs.wasNull()); int d = rs.getInt(4); Assert.assertFalse("D is null!", rs.wasNull()); } Assert.assertEquals("Incorrect row count!", 2, count); }
From source file:dk.dma.msinm.legacy.msi.service.LegacyMsiImportService.java
private Integer getInt(ResultSet rs, String key) throws SQLException { Integer val = rs.getInt(key); return rs.wasNull() ? null : val; }
From source file:dk.dma.msinm.legacy.msi.service.LegacyMsiImportService.java
private String getString(ResultSet rs, String key) throws SQLException { String val = rs.getString(key); return rs.wasNull() ? null : val; }
From source file:dk.dma.msinm.legacy.msi.service.LegacyMsiImportService.java
private Double getDouble(ResultSet rs, String key) throws SQLException { Double val = rs.getDouble(key); return rs.wasNull() ? null : val; }
From source file:dk.dma.msinm.legacy.msi.service.LegacyMsiImportService.java
private Boolean getBoolean(ResultSet rs, String key) throws SQLException { boolean val = rs.getBoolean(key); return rs.wasNull() ? null : val; }
From source file:dk.dma.msinm.legacy.msi.service.LegacyMsiImportService.java
private Date getDate(ResultSet rs, String key) throws SQLException { Timestamp val = rs.getTimestamp(key); return rs.wasNull() ? null : val; }