List of utility methods to do SQL ResultSet
String | createUid(final String[] keys, final ResultSet rs, final String keySeparator) create Uid final StringBuilder uid = new StringBuilder(); if (keys != null && keys.length > 0) { for (String field : keys) { if (uid.length() > 0) { uid.append(keySeparator); uid.append(rs.getString(field)); return uid.toString(); |
List | encodeHeader(ResultSetMetaData metaData) encode Header ArrayList<String> res = new ArrayList<>(); res.add(Integer.toString(metaData.getColumnCount())); for (int i = 1; i <= metaData.getColumnCount(); i++) { String columnName = metaData.getColumnName(i); String columnLabel = metaData.getColumnLabel(i); if (columnLabel == null || columnLabel.equalsIgnoreCase(columnName)) { res.add(columnName); } else { ... |
Optional | extractGeneratedId(ResultSet generatedKeys) extract Generated Id if (generatedKeys.next()) { return Optional.of(generatedKeys.getLong(1)); return Optional.empty(); |
int | extractIntResult(ResultSet rs, ResultSetMetaData rsmd, int index) This method returns an int result at a given index. int count = rsmd.getColumnCount(); if (index > count || index < 1) { throw new Exception("Invalid index"); int type = rsmd.getColumnType(index); switch (type) { case java.sql.Types.INTEGER: case java.sql.Types.SMALLINT: ... |
List | extractResults(ResultSet resultSet) extract Results List<Map<String, ?>> results = new ArrayList<Map<String, ?>>(); while (resultSet.next()) { Map<String, Object> row = new HashMap<String, Object>(); for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { row.put(resultSet.getMetaData().getColumnLabel(i), resultSet.getObject(i)); results.add(row); return results; |
Set | extractResultSetFiledNames(ResultSet result) extract Result Set Filed Names ResultSetMetaData rsmd = result.getMetaData(); Set<String> columnsSet = new HashSet<>(); int columns = rsmd.getColumnCount(); for (int x = 1; x <= columns; x++) { columnsSet.add(rsmd.getColumnName(x)); return columnsSet; |
void | fillRowNames(Map fill Row Names Assert.notNull(metaData, "The column names can't be null."); if (metaData.isEmpty()) { for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { metaData.put(rs.getMetaData().getColumnName(i), rs.getMetaData().getColumnType(i)); |
boolean | hasCompleted(ResultSet rs) has Completed try { return (rs.isClosed() || rs.isAfterLast()); } catch (SQLException e) { return false; |
boolean | hasGeometryField(ResultSet resultSet) Check if the resultset contains a geometry field ResultSetMetaData meta = resultSet.getMetaData(); int columnCount = meta.getColumnCount(); for (int i = 1; i <= columnCount; i++) { if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) { return true; return false; ... |
boolean | isNull(ResultSet rs, String name) is Null rs.getObject(name);
return rs.wasNull();
|