Created
December 9, 2016 10:09
-
-
Save culmat/c2fede9a2e47d638c5f75b98ffb8944f to your computer and use it in GitHub Desktop.
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
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