Skip to content

Instantly share code, notes, and snippets.

@culmat
Created December 9, 2016 10:09
Show Gist options
  • Save culmat/c2fede9a2e47d638c5f75b98ffb8944f to your computer and use it in GitHub Desktop.
Save culmat/c2fede9a2e47d638c5f75b98ffb8944f to your computer and use it in GitHub Desktop.
package common;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class JDBCDebug {
public static Map<String, Object> getEmptyRow(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int colCount = metaData.getColumnCount();
Map<String, Object> columns = new HashMap<String, Object>();
for (int i = 1; i <= colCount; i++) {
columns.put(metaData.getColumnLabel(i), "");
}
return columns;
}
public static Map<String, Object> getRow(ResultSet rs, Map<String, Object> row) throws SQLException {
for (String key : row.keySet()) {
row.put(key, rs.getObject(key));
}
return row;
}
public static Map<String, Object> getRow(ResultSet rs) throws SQLException {
return getRow(rs, getEmptyRow(rs));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment