/**
 * Print the ResultSet object.
 * @param rs the ResultSet object
 */
public static void sqlResultSetPrint(java.sql.ResultSet rs) {
	try {
		java.sql.ResultSetMetaData metaData = rs.getMetaData();
		int columnCount = metaData.getColumnCount();
		for (int i = 1; i <= columnCount; i++) {
			if (i > 1) {
				System.out.print(", ");
			}
			System.out.print(metaData.getColumnLabel(columnCount));
		}
		System.out.println();
		while (rs.next()) {
			for (int i = 0; i <= columnCount; i++) {
				if (i > 1) {
					System.out.print(", ");
				}
				System.out.print(rs.getString(i));
			}
			System.out.println();
		}
		// This is required for further action on the result set.
		rs.beforeFirst();
	} catch (java.sql.SQLException ex) {
		Ts.printErr(ex);
	}
}
 
public static void printErr(java.sql.SQLException ex) {
	System.out.println("SQL State: " + ex.getSQLState());
	System.out.println("Error Code: " + ex.getErrorCode());
	Ts.printErr((java.lang.Exception) ex);
}
 
public static void printErr(java.lang.Exception ex) {
	ex.printStackTrace();
	System.exit(-1);
}


Back to JavaHowTo

Alumni Liaison

To all math majors: "Mathematics is a wonderfully rich subject."

Dr. Paul Garrett