当前位置: 首页>>代码示例>>Java>>正文


Java RowSetMetaDataImpl.setPrecision方法代码示例

本文整理汇总了Java中javax.sql.rowset.RowSetMetaDataImpl.setPrecision方法的典型用法代码示例。如果您正苦于以下问题:Java RowSetMetaDataImpl.setPrecision方法的具体用法?Java RowSetMetaDataImpl.setPrecision怎么用?Java RowSetMetaDataImpl.setPrecision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sql.rowset.RowSetMetaDataImpl的用法示例。


在下文中一共展示了RowSetMetaDataImpl.setPrecision方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initCoffeesMetaData

import javax.sql.rowset.RowSetMetaDataImpl; //导入方法依赖的package包/类
protected void initCoffeesMetaData(CachedRowSet crs) throws SQLException {
    RowSetMetaDataImpl rsmd = new RowSetMetaDataImpl();
    crs.setType(RowSet.TYPE_SCROLL_INSENSITIVE);

    /*
     *  CREATE TABLE COFFEES (
     *   COF_ID INTEGER NOT NULL,
     *   COF_NAME VARCHAR(32) NOT NULL,
     *   SUP_ID INTEGER NOT NULL,
     *   PRICE NUMBERIC(10,2 NOT NULL,
     *   SALES INTEGER NOT NULL,
     *   TOTAL INTEGER NOT NULL,
     *   PRIMARY KEY (COF_ID),
     *   FOREIGN KEY (SUP_ID) REFERENCES SUPPLIERS (SUP_ID) )
     */
    rsmd.setColumnCount(COFFEES_COLUMN_NAMES.length);
    for(int i = 1; i <= COFFEES_COLUMN_NAMES.length; i++){
        rsmd.setColumnName(i, COFFEES_COLUMN_NAMES[i-1]);
        rsmd.setColumnLabel(i, rsmd.getColumnName(i));
    }

    rsmd.setColumnType(1, Types.INTEGER);
    rsmd.setColumnType(2, Types.VARCHAR);
    rsmd.setColumnType(3, Types.INTEGER);
    rsmd.setColumnType(4, Types.NUMERIC);
    rsmd.setPrecision(4, 10);
    rsmd.setScale(4, 2);
    rsmd.setColumnType(5, Types.INTEGER);
    rsmd.setColumnType(6, Types.INTEGER);
    crs.setMetaData(rsmd);
    crs.setTableName(COFFEES_TABLE);

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:CommonRowSetTests.java

示例2: initMetaData

import javax.sql.rowset.RowSetMetaDataImpl; //导入方法依赖的package包/类
/**
 * 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
 * @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);
	boolean isCaseSensitive = numCols > 0 ? rsmd.isCaseSensitive(1) : false;
	for (int col = 1; col <= numCols; col++) {
		md.setAutoIncrement(col, rsmd.isAutoIncrement(col));
		md.setCaseSensitive(col, isCaseSensitive); // fix the MySQL
													// performance
													// issue:http://blog.csdn.net/match_ding/article/details/11078553
		md.setCurrency(col, rsmd.isCurrency(col));
		md.setNullable(col, rsmd.isNullable(col));
		md.setSigned(col, rsmd.isSigned(col));
		md.setSearchable(col, rsmd.isSearchable(col));
		/*
		 * 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, size);
		md.setColumnLabel(col, rsmd.getColumnLabel(col));
		md.setColumnName(col, rsmd.getColumnName(col));
		md.setSchemaName(col, rsmd.getSchemaName(col));
		/*
		 * 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, precision);

		/*
		 * 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, scale);
		md.setTableName(col, rsmd.getTableName(col));
		md.setCatalogName(col, rsmd.getCatalogName(col));
		md.setColumnType(col, rsmd.getColumnType(col));
		md.setColumnTypeName(col, rsmd.getColumnTypeName(col));
	}
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:70,代码来源:CachedRowSetImpl.java


注:本文中的javax.sql.rowset.RowSetMetaDataImpl.setPrecision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。