|
Awake SQL v1.2.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.awakefw.sql.api.util.ResultSetPrinter
public class ResultSetPrinter
Tool to display the content of any JDBC ResultSet
on a print
stream.
(Code extracted/adapted from Oreilly JDBC book).
Note that header columns are left justified and all result columns are right
justified.
Example on our test database awake_example:
Will produce the following output:String sql = "select * from customer limit 5"; PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet rs = preparedStatement.executeQuery(); // Print the result set on System.out: ResultSetPrinter resultSetPrinter = new ResultSetPrinter(rs, System.out); resultSetPrinter.print(); rs.first(); System.out.println(); // Print the result set on System.out with CSV format: resultSetPrinter = new ResultSetPrinter(rs, System.out, true); resultSetPrinter.print(); preparedStatement.close(); rs.close();
customer_id | title | fname | lname | addressline | town | zipcode | phone --------------------------------------------------------------------------------------------- 1 | Sir | NULL | Smith_1 | 1, César Avenue | JavaLand_1 | 145 | 1-12345678 2 | Sir | NULL | Smith_2 | 2, César Avenue | JavaLand_2 | 245 | 2-12345678 3 | Sir | NULL | Smith_3 | 3, César Avenue | JavaLand_3 | 345 | 3-12345678 4 | Sir | NULL | Smith_4 | 4, César Avenue | JavaLand_4 | 445 | 4-12345678 5 | Sir | NULL | Smith_5 | 5, César Avenue | JavaLand_5 | 545 | 5-12345678 (5 rows) customer_id;title;fname;lname;addressline;town;zipcode;phone 1;Sir;NULL;Smith_1;1, César Avenue;JavaLand_1;145;1-12345678 2;Sir;NULL;Smith_2;2, César Avenue;JavaLand_2;245;2-12345678 3;Sir;NULL;Smith_3;3, César Avenue;JavaLand_3;345;3-12345678 4;Sir;NULL;Smith_4;4, César Avenue;JavaLand_4;445;4-12345678 5;Sir;NULL;Smith_5;5, César Avenue;JavaLand_5;545;5-12345678
Constructor Summary | |
---|---|
ResultSetPrinter(ResultSet resultSet,
PrintStream printStream)
Constructor to use to display a human readable ResultSet . |
|
ResultSetPrinter(ResultSet resultSet,
PrintStream printStream,
boolean formatForCSV)
Constructor to use to display a human readable or a CSV formated ResultSet |
Method Summary | |
---|---|
void |
print()
Prints the Result Set. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResultSetPrinter(ResultSet resultSet, PrintStream printStream)
ResultSet
.
resultSet
- the result set to displayprintStream
- the print stream to use for displaypublic ResultSetPrinter(ResultSet resultSet, PrintStream printStream, boolean formatForCSV)
ResultSet
resultSet
- the result set to displayprintStream
- the print stream to use for displayformatForCSV
- if true, result will be formatted for CSV format with ";"
separator instead of "|"Method Detail |
---|
public void print() throws SQLException
SQLException
|
Awake SQL v1.2.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |