I actually got it to work. Here's the final code:
public void sqlQuery1(String query) {
System.out.println("Enter you sql query:");
this.query = scan.nextLine();
Connection conn = getConnection();
Statement stmt = null;
try {
stmt = conn.createStatement();
boolean notDone = true;
while(notDone) {
ResultSet rs = stmt.executeQuery(this.query);
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
for(int i = 1; i <= columnCount; i++) {
int columnWidth = rsmd.getColumnDisplaySize(i) + 5;
System.out.format("%-" + columnWidth + "s", rsmd.getColumnName(i));
} //for
System.out.println();
while(rs.next()) {
for(int i = 1; i <= columnCount; i++) {
int columnWidth = rsmd.getColumnDisplaySize(i) + 5;
System.out.format("%-" + columnWidth + "s", rs.getString(i));
} //for
System.out.println();
} //rs.next while
notDone = false;
} //notDone while
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} catch (Exception e) {
System.out.println(e.toString());
}finally {
try {
if(stmt!=null)
stmt.close();
} catch(SQLException se2) {
try {
if(conn!=null)
conn.close();
} catch(SQLException se) {
se.printStackTrace();
} //last catch
} //finally
} //original try
System.out.println();
System.out.println();
}