List of utility methods to do SQL Table Column
boolean | columnExists(Connection con, String tableName, String columnName) Tests if a column exists in the database if (tableName == null) { throw new NullPointerException("tableName cannot be null"); if (columnName == null) { throw new NullPointerException("columnName cannot be null"); ResultSet res = con.getMetaData().getColumns(null, null, tableName, columnName); while (res.next()) { ... |
boolean | columnExists(Connection connection, String table, String column) column Exists ResultSet columns = null; boolean exists; try { columns = connection.getMetaData().getColumns(null, null, table, column); exists = columns.next(); } finally { if (columns != null) { columns.close(); ... |
Set | columnLabels(final ResultSet results) column Labels final ResultSetMetaData rsmd = results.getMetaData(); final int columnCount = rsmd.getColumnCount(); final Set<String> columnLabels = new HashSet<String>(columnCount); for (int i = 1; i <= columnCount; i++) { columnLabels.add(rsmd.getColumnLabel(i)); return columnLabels; |
boolean | containsColumn(ResultSet rs, String columnName) contains Column try { rs.findColumn(columnName); return true; } catch (SQLException e) { return false; |
String | extractColumnTypeName(ResultSetMetaData resultSetMetaData, int index) extract Column Type Name return resultSetMetaData.getColumnTypeName(index);
|
int | generateKey(Statement statement, String TableName, String KeyColumn) generate Key String sql = "SELECT MAX(" + KeyColumn + ") FROM " + TableName; return getQueryInt(statement, sql); |
ResultSet | getAllFromSensorDb(final Connection jdbcConnection, final String tableName, final String orderByColumn) get All From Sensor Db Logger.getAnonymousLogger().log(Level.INFO, "Querying sensor DB to stream all data."); Statement stmt = jdbcConnection.createStatement(); stmt.setFetchSize(10000); stmt.setQueryTimeout(0); String sql = MessageFormat.format("SELECT * FROM {0} {1} ORDER BY {2}", tableName, PREDICATE, orderByColumn); return stmt.executeQuery(sql); |
String | getColumn(ResultSet result, int col) Get a string from a result set, trimming trailing blanks. String s = result.getString(col); if (s != null) { s = s.trim(); return s; |
int | getColumnDisplaySize(int col, ResultSetMetaData rsmd) get Column Display Size int columnSize = rsmd.getColumnDisplaySize(col); return columnSize; |
int | getColumnIndexFromColumnName(ResultSetMetaData metaData, String columnName) Returns the column index for the guven column name. for (int i = 1; i <= metaData.getColumnCount(); i++) { String tmpName = metaData.getColumnLabel(i); if (tmpName.equalsIgnoreCase(columnName)) { return i; return -1; |