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

ResultSetgetResultSet(Connection conn, String query)
get Result Set
ResultSet rs = null;
try {
    System.out.println(query);
    System.out.println(conn);
    Statement st = conn.createStatement();
    rs = st.executeQuery(query);
    if (!rs.next())
        rs = null;
...
ResultSetgetResultSet(Connection connection, String query)
to get a result set of a query
ResultSet rs;
PreparedStatement st = connection.prepareStatement(query);
rs = st.executeQuery();
return rs;
ResultSetgetResultSet(String sql)
get Result Set
Connection conn;
Statement stmt;
ResultSet rs = null;
try {
    conn = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/rspamd?characterEncoding=utf8&useSSL=true", "root", "root");
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
...
ArrayListgetResultSetColnumNames(ResultSet rs)
get Result Set Colnum Names
ArrayList<String> list = null;
if (rs == null)
    return list;
list = new ArrayList<String>();
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
for (int i = 1; i <= colCount; i++) {
    String colName = rsmd.getColumnName(i);
...
String[]getResultSetColumns(ResultSet rs)
get Result Set Columns
ResultSetMetaData md = rs.getMetaData();
int nCols = md.getColumnCount();
String[] ret = new String[nCols];
for (int i = 0; i < ret.length; i++) {
    ret[i] = md.getColumnName(i + 1);
return (ret);
DategetResultSetDateValue(ResultSet rs, String sColumnName)
Converts a resultset item into a java.util.Date.
Timestamp ts = rs.getTimestamp(sColumnName);
if (ts != null)
    return new Date(ts.getTime());
return null;
ResultSetGetResultSetFromQuery(String command)
Preforms an SQL query and returns the result set.
if (mStatement != null) {
    try {
        return mStatement.executeQuery(command);
    } catch (SQLException e) {
        System.out.println(mSqlHelperPrefix + e);
        return null;
System.out.println("SQLHelper: statement==null");
return null;
ResultSetgetResultSetFromQueryAgainstDefaultConnection(String sql)
get Result Set From Query Against Default Connection
Connection c = getDefaultDerbyConnection();
ResultSet rs = c.createStatement().executeQuery(sql);
return rs;
ResultSetgetResultSetInstance(Connection conn, String sql)
This method gets the instance of the result Set
Statement stmt = null;
ResultSet rs = null;
try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
} catch (SQLException e) {
    throw new RuntimeException("Could not execute query:" + sql, e);
return rs;
HashMapgetResultSetMetaData(ResultSet rs)
get Result Set Meta Data
HashMap lhs = new HashMap(5);
ResultSetMetaData rsmd = rs.getMetaData();
int colSize = rsmd.getColumnCount();
for (int i = 1; i < colSize + 1; i++) {
    lhs.put(rsmd.getColumnName(i).toUpperCase(), getJavaType(rsmd.getColumnName(i), rsmd.getColumnType(i),
            rsmd.getPrecision(i), rsmd.getScale(i)));
return lhs;
...