Java Utililty Methods SQL ResultSet

List of utility methods to do SQL ResultSet

Description

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

Method

String[]arrayOfResult(ResultSet rs)
array Of Result
ResultSetMetaData rsm = rs.getMetaData();
String ret[] = new String[rsm.getColumnCount()];
for (int i = 0; i < ret.length; i++) {
    ret[i] = rs.getString(i + 1);
return ret;
voidcleanupAfterQuery(final ResultSet rs, final Statement stmt)
cleanup After Query
if (rs != null) {
    rs.close();
if (stmt != null) {
    stmt.close();
voidcleanupConnection(ResultSet rs, Statement stmt, Connection conn)
cleanup Connection
if (rs != null) {
    try {
        rs.close();
    } catch (SQLException ignore) { 
if (stmt != null) {
    try {
...
voidcleanupJDBCResouce(ResultSet rs, Statement stmt, String oldCatalog, Connection conn)
cleanup JDBC Resouce
try {
    if (rs != null)
        rs.close();
} catch (SQLException e) {
    e.printStackTrace();
try {
    if (stmt != null)
...
Object[][]consume(ResultSet rs)
consume
ResultSetMetaData rsmd = rs.getMetaData();
ArrayList results = new ArrayList();
int colCount = rsmd.getColumnCount();
while (rs.next()) {
    Object[] row = new Object[colCount];
    for (int i = 1; i <= colCount; ++i) {
        row[i - 1] = rs.getObject(i);
    results.add(row);
return toOutArray(results, colCount);
Map[]consume2(ResultSet rs)
consume
ResultSetMetaData rsmd = rs.getMetaData();
ArrayList results = new ArrayList();
int colCount = rsmd.getColumnCount();
while (rs.next()) {
    Map row = new HashMap();
    for (int i = 1; i <= colCount; ++i) {
        Object val = rs.getObject(i);
        row.put(rsmd.getColumnName(i), val);
...
voidcopyInt(ResultSet rs, int sourcePos, PreparedStatement stmt, int destPos)
copy Int
final int value = rs.getInt(sourcePos);
if (rs.wasNull())
    stmt.setNull(destPos, Types.INTEGER);
else
    stmt.setInt(destPos, value);
PreparedStatementcreateLargeResultSetPreparedStatement(Connection conn, String sql)
Returns a new prepared statement on the specified connection with the necessary options to avoid running out of memory when reading a large result set.
PreparedStatement st = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
st.setFetchSize(Integer.MIN_VALUE);
return st;
StatementcreateLargeResultSetStatement(Connection conn)
Returns a new statement on the specified connection with the necessary options to avoid running out of memory when reading a large result set.
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
TabularDatacreateTable(ResultSet rs)
create Table
ResultSetMetaData rsMetaData = rs.getMetaData();
int numCols = rsMetaData.getColumnCount();
String[] headers = new String[numCols];
OpenType[] allTypes = new OpenType[numCols];
Vector[] values = new Vector[numCols];
Object[] allValues = new Object[numCols];
for (int i = 0; i < numCols; i++) {
    headers[i] = rsMetaData.getColumnName(i + 1);
...