@Override public Byte fromResult(ResultSet results, int column) throws SQLException { return results.getByte(column); }
@Override public byte readByte(ResultSet results, int column) throws SQLException { return results.getByte(column); }
@Override public byte getByte(int columnIndex) throws SQLException { return rs.getByte(columnIndex); }
@Override public byte getByte(String columnLabel) throws SQLException { return rs.getByte(columnLabel); }
public static Object getRSData(ResultSet rs, String columnName, int jdbcType) throws SQLException { if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) { return rs.getByte(columnName); } else { return rs.getObject(columnName); } }
/** * @see java.sql.ResultSet#getByte(int) */ @Override public byte getByte(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getByte(columnIndex); } catch (SQLException se) { throw new InvalidResultSetAccessException(se); } }
/** * {@inheritDoc} */ @Override public Byte get(final ResultSet rs, final int index, final int dbSqlType) throws SQLException { return Byte.valueOf(rs.getByte(index)); }
@Override public byte getByte(int columnIndex) throws SQLException { try { return rs.getByte(columnIndex); } catch (Throwable t) { throw checkException(t); } }
@Override public byte getByte(String columnLabel) throws SQLException { try { return rs.getByte(columnLabel); } catch (Throwable t) { throw checkException(t); } }
public Object get(ResultSet rs, String colName) throws SQLException { byte re = rs.getByte(colName); return rs.wasNull() ? null : re; }
@Override protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { return javaTypeDescriptor.wrap( rs.getByte( name ), options ); }
@Override public void run() throws Exception { rs.getByte("id"); } });
@Override public void run() throws Exception { rs.getByte(1); } });
@Override public byte resultSet_getByte(ResultSetProxy rs, String columnLabel) throws SQLException { if (this.pos < filterSize) { return nextFilter() .resultSet_getByte(this, rs, columnLabel); } return rs.getResultSetRaw() .getByte(columnLabel); }
@Override public byte resultSet_getByte(ResultSetProxy rs, int columnIndex) throws SQLException { if (this.pos < filterSize) { return nextFilter() .resultSet_getByte(this, rs, columnIndex); } return rs.getResultSetRaw() .getByte(columnIndex); }
public Object getValFromRS(ESMapping mapping, ResultSet resultSet, String fieldName, String columnName) throws SQLException { String esType = getEsType(mapping, fieldName); Object value = resultSet.getObject(columnName); if (value instanceof Boolean) { if (!"boolean".equals(esType)) { value = resultSet.getByte(columnName); } } // 如果是对象类型 if (mapping.getObjFields().containsKey(fieldName)) { return ESSyncUtil.convertToEsObj(value, mapping.getObjFields().get(fieldName)); } else { return ESSyncUtil.typeConvert(value, esType); } }
@Override public void run(Connection conn) throws Exception { try (PreparedStatement stmt = conn.prepareStatement("SELECT 'zzz'")) { ResultSet rs = stmt.executeQuery(); rs.next(); rs.getByte(1); } } }, "0700B", "Cannot convert to byte");
@Override public byte getByte(String columnLabel) throws SQLException { SQLException e = null; try { byte value = delegate.getByte(columnLabel); eventListener.onAfterResultSetGet(resultSetInformation, columnLabel, value, null); return value; } catch (SQLException sqle) { e = sqle; eventListener.onAfterResultSetGet(resultSetInformation, columnLabel, null, e); throw e; } }
@Test public void testIgnoredWarning() throws Exception { String sql = "SELECT forename from custmr"; SQLWarning warnings = new SQLWarning("My warning"); given(this.resultSet.next()).willReturn(false); given(this.connection.createStatement()).willReturn(this.preparedStatement); given(this.preparedStatement.getWarnings()).willReturn(warnings); // Too long: truncation this.template.setIgnoreWarnings(true); this.template.query(sql, rs -> { rs.getByte(1); }); verify(this.resultSet).close(); verify(this.preparedStatement).close(); verify(this.connection).close(); }
/** * Mock objects allow us to produce warnings at will */ @Test public void testFatalWarning() throws Exception { String sql = "SELECT forename from custmr"; SQLWarning warnings = new SQLWarning("My warning"); given(this.resultSet.next()).willReturn(false); given(this.preparedStatement.getWarnings()).willReturn(warnings); given(this.connection.createStatement()).willReturn(this.preparedStatement); JdbcTemplate t = new JdbcTemplate(this.dataSource); t.setIgnoreWarnings(false); this.thrown.expect(SQLWarningException.class); this.thrown.expect(exceptionCause(sameInstance(warnings))); try { t.query(sql, rs -> { rs.getByte(1); }); } finally { verify(this.resultSet).close(); verify(this.preparedStatement).close(); verify(this.connection).close(); } }