List of utility methods to do SQL Table Column
String | readString(final ResultSet resultSet, final String columnName) Helper function that exists primarily to fool poedit to stop localizing column names. return resultSet.getString(columnName);
|
String | readStringFromBlob(ResultSet resultSet, String columnLabel) read String From Blob try { Blob factoryBlob = resultSet.getBlob(columnLabel); return new String(factoryBlob.getBytes(1L, (int) factoryBlob.length()), StandardCharsets.UTF_8); } catch (SQLException e) { throw new RuntimeException(e); |
int | resultSetAsCount(ResultSet rs, String countColumn) result Set As Count int count = 0; if (rs != null) { try { while (rs.next()) { count = Integer.parseInt(rs.getString(countColumn)); } catch (Exception e) { e.printStackTrace(); ... |
boolean | resultSetContainsColumn(ResultSet rs, String column) Scans through a result set's metadata in an attempt to find a column ResultSetMetaData meta = rs.getMetaData(); int total = meta.getColumnCount(); for (int i = 1; i <= total; i++) { if (meta.getColumnName(i).equals(column)) { return true; return false; ... |
boolean | resultSetHasColumn(ResultSet rs, String sColumnName) Determines if a column exists within the given resultset if (rs == null) return false; ResultSetMetaData rsmd = rs.getMetaData(); int iCols = rsmd.getColumnCount(); for (int i = 1; i <= iCols; i++) if (rsmd.getColumnName(i).equalsIgnoreCase(sColumnName)) return true; ... |
String | resultSetToOneColumnAsCommamaSeparatedString(ResultSet rs) result Set To One Column As Commama Separated String if (rs == null) return null; try { ResultSetMetaData metaData = rs.getMetaData(); int numberOfColumns = metaData.getColumnCount(); if (numberOfColumns > 1) return null; StringBuilder columnValues = new StringBuilder(numberOfColumns); ... |
List | resultSetToOneColumnAsList(ResultSet rs) result Set To One Column As List if (rs == null) return null; try { ResultSetMetaData metaData = rs.getMetaData(); int numberOfColumns = metaData.getColumnCount(); if (numberOfColumns > 1) return null; List<Object> rows = new ArrayList<Object>(numberOfColumns); ... |
String | resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column) result Set To String Format StringBuilder sb = new StringBuilder(); ResultSetMetaData metadata = rs.getMetaData(); int colmumnCount = metadata.getColumnCount(); if (column) { for (int i = 1; i <= colmumnCount; i++) { sb.append(quote).append(metadata.getColumnName(i)).append(quote); if (i + 1 <= colmumnCount) { sb.append(separator); ... |
Object | resultSetValue(ResultSet resultSet, Class> parameterClass, Object object, String columnLabel) result Set Value Object value = null; if (parameterClass.equals(String.class)) { value = resultSet.getString(columnLabel); } else if (parameterClass.equals(Integer.class)) { value = resultSet.getInt(columnLabel); } else if (parameterClass.equals(Float.class)) { value = resultSet.getFloat(columnLabel); } else if (parameterClass.equals(Long.class)) { ... |
ResultSet | retrieveCoulmns(String tableName, String columnArray[], Statement statement, long offset, long numberOfRecords) retrieve Coulmns String query = "select "; for (String column : columnArray) { query = query + " " + column + " ,"; query = query.substring(0, query.length() - 1); query = query + "from " + tableName + " Limit " + offset + ", " + numberOfRecords + ";"; return statement.executeQuery(query); |