List of utility methods to do SQL ResultSet Read
T | getEnum(ResultSet rs, int index, Class get Enum int value = rs.getInt(index); for (T t : type.getEnumConstants()) { if (t.ordinal() == value) return t; return null; |
T | getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues) get Enum From Result Set return getEnumFromResultSet(rset, field.name(), enumValues);
|
Class | getExpectedType(ResultSet resultSet, int columnIndex) get Expected Type Class expectedType; ResultSetMetaData metaData = resultSet.getMetaData(); int sqlType = metaData.getColumnType(columnIndex); int decimalDigits = metaData.getScale(columnIndex); expectedType = getClassByJdbcType(sqlType, decimalDigits); return expectedType; |
String | getExplainPlan(ResultSet rs) get Explain Plan StringBuilder buf = new StringBuilder(); while (rs.next()) { buf.append(rs.getString(1)); buf.append('\n'); if (buf.length() > 0) { buf.setLength(buf.length() - 1); return buf.toString(); |
String[] | getFieldNames(ResultSet rs) Return field names if (rs == null) return null; ResultSetMetaData metaData = rs.getMetaData(); int col_num = metaData.getColumnCount(); String[] col_names = new String[col_num]; for (int i = 0; i < col_num; i++) col_names[i] = metaData.getColumnName(i + 1); return col_names; ... |
List | getFieldsPresentInResultSet(ResultSet rs) get Fields Present In Result Set List<String> fieldsPresentInResultSet = new ArrayList<String>(); ResultSetMetaData metaData = rs.getMetaData(); for (int index = 1; index <= metaData.getColumnCount(); index++) { fieldsPresentInResultSet.add(metaData.getColumnLabel(index).toLowerCase()); return fieldsPresentInResultSet; |
int | getFirstGeometryFieldIndex(ResultSet resultSet) Find the first geometry field name of a resultSet. ResultSetMetaData meta = resultSet.getMetaData(); int columnCount = meta.getColumnCount(); for (int i = 1; i <= columnCount; i++) { if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) { return i; return -1; ... |
int | getFirstInt(ResultSet resultSet) Returns int value of very first column in result set. if (resultSet.next() == true) { return resultSet.getInt(1); return -1; |
Flags | getFlags(ResultSet rs) get Flags Flags flags = new Flags(); for (int i = 0; i < attrArray.length; i++) { if ("Y".equals(rs.getString(attrArray[i]))) { flags.add(flagArray[i]); return flags; |
long | getGeneratedIdFromResultSet(ResultSet resultSet) get Generated Id From Result Set long orderId = -1; while (resultSet != null && resultSet.next()) { orderId = resultSet.getLong(1); return orderId; |