Executing query...["+selectQry+"]
");
// Create a statement and execute the query on it
s = c.createStatement();
s.execute(selectQry);
// Get result set
r = s.getResultSet();
rm = r.getMetaData();
// Display data
int count = rm.getColumnCount();
// Output each row from the query
while (r.next()) {
for(int i = 1; i <= rm.getColumnCount(); i++) {
// Output each column, and it's value
out.println("
[Column " + i + " - " + rm.getColumnName(i) + "] " + r.getString(rm.getColumnName(i)));
}
out.println("");
}
// Clean up
s.close();
c.close();
} else {
out.println("ERROR: No connection");
}
} catch (Exception e) {
out.println("Errors occurred: " + e.toString());
throw e;
} finally {
// Always make sure result sets and statements are closed,
// and the connection is returned to the pool
if(r != null) {
try { r.close(); } catch(Exception e) {}
r = null;
}
if(s != null) {
try { s.close(); } catch(Exception e) {}
s = null;
}
if(c != null) {
try { c.close(); } catch(Exception e) {}
c = null;
}
}
// Done
out.println("