Here you can find the source of printResults(ResultSet rst)
Parameter | Description |
---|---|
rst | the resultSet returned from the query execution. |
Parameter | Description |
---|---|
SQLException | if a database error occurs |
public static int printResults(ResultSet rst) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { /**// ww w . ja v a 2 s . c o m * Helper method to print out the resultSet. * * @param rst the resultSet returned from the query execution. * @return the number of tuples returned * @throws SQLException * if a database error occurs */ public static int printResults(ResultSet rst) throws SQLException { // if(!rst.isBeforeFirst()){ // throw new SQLException("Result set not before first"); // } // Print out your results ResultSetMetaData meta = rst.getMetaData(); int numColumns = meta.getColumnCount(); System.out.print(meta.getColumnName(1)); for (int j = 2; j <= meta.getColumnCount(); j++) System.out.print(", " + meta.getColumnName(j)); System.out.println(); int count = 0; while (rst.next()) { System.out.print(rst.getObject(1)); for (int j = 2; j <= numColumns; j++) System.out.print(", " + rst.getObject(j)); System.out.println(); count++; } return count; } }