Example usage for javax.sql.rowset RowSetMetaDataImpl setScale

List of usage examples for javax.sql.rowset RowSetMetaDataImpl setScale

Introduction

In this page you can find the example usage for javax.sql.rowset RowSetMetaDataImpl setScale.

Prototype

public void setScale(int columnIndex, int scale) throws SQLException 

Source Link

Document

Sets the number of digits to the right of the decimal point in a value stored in the designated column to the given number.

Usage

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/*from  w ww.ja va2  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();
    }
}