List of utility methods to do SQL ResultSet Read
int | getNullableInt(ResultSet resultSet, String column, int fallback) Loads the value for the given column from a ResultSet . int value = resultSet.getInt(column); return (value == 0 && resultSet.wasNull()) ? fallback : value; |
Long | getNullableLong(ResultSet rs, String columnName) Returns the long value of a column, or null when appropriate. long longValue = rs.getLong(columnName); return rs.wasNull() ? null : longValue; |
Date | getNullDate(ResultSet result, String columnName) Reads date from result set. long birthTime = result.getLong(columnName); if (birthTime == NULL_VALUE) { return null; return new Date(birthTime); |
String | getNumber(ResultSet rs, String name) get Number try { return "\"" + name + "\":" + rs.getLong(name) + ""; } catch (SQLException ex) { return "\"" + name + "\":\"error\""; |
int | getNumberColumns(ResultSet rs) get Number Columns ResultSetMetaData md = rs.getMetaData(); int nCols = md.getColumnCount(); return (nCols); |
int | getNumRows(ResultSet query) get Num Rows int numRows = 0; try { if (query.last()) numRows = query.getRow(); } catch (SQLException e) { e.printStackTrace(); return numRows; ... |
T | getObject(ResultSet resultSet, int columnCount, Map get Object try { T entity = cls.newInstance(); if (fields != null && columnLabel != null) { for (int j = 0; j < fields.length; j++) { Object object = columnLabelMap.get(columnLabel[j]) == null ? null : resultSet.getObject(columnLabel[j]); if (object != null) { String fieldName = fields[j]; ... |
Object | getObject(ResultSet rs, int columnIndex, Class type) get Object if (BigDecimal.class == type) return rs.getBigDecimal(columnIndex); if (Blob.class == type) return rs.getBlob(columnIndex); if (boolean.class == type || Boolean.class == type) return rs.getBoolean(columnIndex); if (byte.class == type || Byte.class == type) return rs.getByte(columnIndex); ... |
Object | getObject(ResultSet set, int columnIndex) Get Object by special column index Object object = null; try { object = set.getObject(columnIndex); } catch (SQLException e) { if (NULLDATE.equals(set.getString(columnIndex))) { object = null; } else { throw e; ... |
Object | getObjectByTypeCoercion(ResultSet resultSet, int index, int dataType) get Object By Type Coercion switch (dataType) { case Types.TIMESTAMP: return resultSet.getTimestamp(index); case Types.CLOB: return resultSet.getString(index); case Types.BLOB: return resultSet.getString(index); default: ... |