List of usage examples for javax.sql.rowset RowSetMetaDataImpl setTableName
public void setTableName(int columnIndex, String tableName) throws SQLException
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Initializes the given <code>RowSetMetaData</code> object with the values * in the given <code>ResultSetMetaData</code> object. * * @param md the <code>RowSetMetaData</code> object for this * <code>CachedRowSetImpl</code> object, which will be set with * values from rsmd/* w ww . j ava 2 s . c om*/ * @param rsmd the <code>ResultSetMetaData</code> object from which new * values for md will be read * @throws SQLException if an error occurs */ private void initMetaData(RowSetMetaDataImpl md, ResultSetMetaData rsmd) throws SQLException { int numCols = rsmd.getColumnCount(); md.setColumnCount(numCols); for (int col = 1; col <= numCols; col++) { md.setAutoIncrement(col, rsmd.isAutoIncrement(col)); if (rsmd.isAutoIncrement(col)) updateOnInsert = true; md.setCaseSensitive(col, false); md.setCurrency(col, false); md.setNullable(col, rsmd.isNullable(col)); md.setSigned(col, rsmd.isSigned(col)); md.setSearchable(col, false); /* * The PostgreSQL drivers sometimes return negative columnDisplaySize, * which causes an exception to be thrown. Check for it. */ int size = rsmd.getColumnDisplaySize(col); if (size < 0) { size = 0; } md.setColumnDisplaySize(col, 0); if (StringUtils.isNotBlank(rsmd.getColumnLabel(col))) { md.setColumnLabel(col, rsmd.getColumnLabel(col).toLowerCase()); } if (StringUtils.isNotBlank(rsmd.getColumnName(col))) { md.setColumnName(col, rsmd.getColumnName(col).toLowerCase()); } md.setSchemaName(col, null); /* * Drivers return some strange values for precision, for non-numeric data, including reports of * non-integer values; maybe we should check type, & set to 0 for non-numeric types. */ int precision = rsmd.getPrecision(col); if (precision < 0) { precision = 0; } md.setPrecision(col, 0); /* * It seems, from a bug report, that a driver can sometimes return a negative * value for scale. javax.sql.rowset.RowSetMetaDataImpl will throw an exception * if we attempt to set a negative value. As such, we'll check for this case. */ int scale = rsmd.getScale(col); if (scale < 0) { scale = 0; } md.setScale(col, 0); md.setTableName(col, null); md.setCatalogName(col, null); md.setColumnType(col, -1); md.setColumnTypeName(col, null); } if (conn != null) { // JDBC 4.0 mandates as does the Java EE spec that all DataBaseMetaData methods // must be implemented, therefore, the previous fix for 5055528 is being backed out dbmslocatorsUpdateCopy = conn.getMetaData().locatorsUpdateCopy(); } }
From source file:org.apache.hadoop.hive.jdbc.storagehandler.AtsdDBRecordReader.java
private ResultSet replaceDotsInColumnNames(ResultSet resultSet) throws SQLException { ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount > 0) { CachedRowSetImpl crs = new CachedRowSetImpl(); crs.populate(resultSet);//from w w w . j av a 2 s .co m RowSetMetaDataImpl rwsm = new RowSetMetaDataImpl(); rwsm.setColumnCount(columnCount); for (int i = 1; i <= columnCount; i++) { String columnName = metaData.getColumnName(i); if (columnName.contains(".")) { columnName = columnName.replaceAll("\\.", "\\$"); } rwsm.setColumnName(i, columnName); rwsm.setColumnLabel(i, metaData.getColumnLabel(i)); rwsm.setCatalogName(i, metaData.getCatalogName(i)); rwsm.setColumnType(i, metaData.getColumnType(i)); rwsm.setColumnTypeName(i, metaData.getColumnTypeName(i)); rwsm.setSchemaName(i, metaData.getSchemaName(i)); rwsm.setTableName(i, metaData.getTableName(i)); } crs.setMetaData(rwsm); return crs; } return resultSet; }