Last active
August 29, 2015 14:05
-
-
Save rdp/7238044dc095a14497e7 to your computer and use it in GitHub Desktop.
output to stdout jdbc all rows and columns of a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void spitOutAllTableRows(String tableName, Connection conn) { | |
try { | |
System.out.println("current " + tableName + " is:"); | |
try (PreparedStatement selectStmt = conn.prepareStatement( | |
"SELECT * from " + tableName, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); | |
ResultSet rs = selectStmt.executeQuery()) { | |
if (!rs.isBeforeFirst()) { | |
System.out.println("no rows found"); | |
} else { | |
while (rs.next()) { | |
for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) { | |
System.out.print(" " + rs.getMetaData().getColumnName(i) + "=" + rs.getObject(i)); | |
} | |
System.out.println(""); | |
} | |
} | |
} | |
} | |
catch (SQLException e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment