Java Utililty Methods SQL ResultSet Read

List of utility methods to do SQL ResultSet Read

Description

The list of methods to do SQL ResultSet Read are organized into topic(s).

Method

ListgetArrayFromResultSet(ResultSet rs, String field)
Returns a string list corresponding to the given field on the given ResultSet.
List<String> result;
try {
    Array arrayChunks = rs.getArray(field);
    String[] chunks = (String[]) arrayChunks.getArray();
    result = Arrays.asList(chunks);
    if (result.contains(null)) {
        result = new ArrayList<String>();
} catch (Exception e) {
    result = new ArrayList<String>();
return result;
StringgetAsString(ResultSet res, String field)
get As String
String ret = res.getString(field);
if (ret == null) {
    return "";
} else {
    return ret;
voidgetBestRowId(String schema, String tableName, int scope, String nullable, ResultSet[] rs)
get Best Row Id
Connection conn = DriverManager.getConnection("jdbc:default:connection");
boolean tf = true;
if (nullable.equals("false"))
    tf = false;
rs[0] = conn.getMetaData().getBestRowIdentifier(null, schema.trim(), tableName.trim(), scope, tf);
BigIntegergetBigInteger(ResultSet resultSet, int columnIndex)
get Big Integer
BigDecimal value = resultSet.getBigDecimal(columnIndex);
return value == null ? null : value.toBigInteger();
BigIntegergetBigIntegerFromResultSet(ResultSet rs, String db_name)
get Big Integer From Result Set
String n = rs.getString(db_name);
return rs.wasNull() ? null : new BigInteger(n);
ObjectgetBigObject(ResultSet set, int columnIndex)
Get Object by special column index
Object object = null;
try {
    object = set.getObject(columnIndex);
    if (object != null && object instanceof Clob) {
        Reader is = ((Clob) object).getCharacterStream();
        BufferedReader br = new BufferedReader(is);
        String str = br.readLine();
        StringBuffer sb = new StringBuffer();
...
CalendargetCalendar(ResultSet resultSet, String columnName)
Transforms a given column from the java.sql.ResultSet from a java.sql.Timestamp to a java.util.Calendar.
return getCalendar(resultSet.getTimestamp(columnName));
StringgetCharacterStream(ResultSet resultSet, String columnName)
Returns a string value using a given SQL result set and column name.
String value = null;
if (resultSet != null && columnName != null) {
    Reader reader = resultSet.getCharacterStream(columnName);
    if (reader != null) {
        StringBuffer buffer = new StringBuffer();
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line = bufferedReader.readLine();
        while (line != null) {
...
ListgetChunkDelimiters(ResultSet rs, int tsColumnIndex, int chunkSize)
A convenient method to break down the total number of rows to delete/update into smaller chunks.
ArrayList list = new ArrayList(10);
int rowCount = 0;
while (rs.next()) {
    if (++rowCount == chunkSize) {
        rowCount = 0;
        list.add(Long.valueOf(rs.getLong(tsColumnIndex)));
list.add(Long.valueOf(System.currentTimeMillis() + 60000));
return list;
StringgetClassName(ResultSetMetaData meta, int index)
Returns a column's java class name.
switch (meta.getColumnType(index)) {
case Types.NUMERIC:
    int precision = meta.getPrecision(index);
    if (meta.getScale(index) == 0) {
        if (precision > 18) {
            return "java.math.BigInteger";
        } else if (precision > 9) {
            return "java.lang.Long";
...