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


Java ResultSetMetaData.getPrecision方法代码示例

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


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

示例1: fill

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
boolean fill(ResultSetMetaData mt, int nColId)	// Fill from the meta data of a result set
{
	try
	{
		m_csColName = mt.getColumnName(nColId);
		m_nTypeId = mt.getColumnType(nColId);
		m_nPrecision = mt.getPrecision(nColId);
		m_nScale = mt.getScale(nColId);
		return true;
	}
	catch (SQLException e)
	{
		Log.logCritical("Exception catched While filling DB table's Column Description:" + e.toString());
	}
	return false;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:17,代码来源:ColDescription.java

示例2: toString

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private static String toString(ResultSetMetaData metadata, int colNum) throws SQLException {
  return "ResultSetMetaData(" + colNum + ")[" +
      "columnName='" + metadata.getColumnName(colNum) + '\'' +
      ", type='" + metadata.getColumnType(colNum) + '\'' +
      ", nullable=" + metadata.isNullable(colNum) +
      ", displaySize=" + metadata.getColumnDisplaySize(colNum) +
      ", precision=" + metadata.getPrecision(colNum) +
      ", scale=" + metadata.getScale(colNum) +
      ", signed=" + metadata.isSigned(colNum) +
      ", className='" + metadata.getColumnClassName(colNum) + '\'' +
      ']';
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:13,代码来源:PreparedStatementTest.java

示例3: getByteValue

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public byte[] getByteValue(ResultSet resultSet, int nCol1Based, boolean bEbcdicOutput)
{
	try
	{
		ResultSetMetaData rsMetaData = resultSet.getMetaData();

		int nNbDigits = rsMetaData.getPrecision(nCol1Based);
		int nNbDecimals = rsMetaData.getScale(nCol1Based);
		Asserter.assertIfFalse(nNbDigits == m_nNbDigits);
		Asserter.assertIfFalse(nNbDecimals == m_nNbDecimals);

		if((nNbDigits % 2) == 0)
			nNbDigits++;
		int nNbCharsInComp3 = (nNbDigits / 2) + 1;
		
		BigDecimal bd = resultSet.getBigDecimal(nCol1Based);
		DecBase decValue = DecBase.toDec(bd);
		
		byte [] aBytes = new byte[nNbCharsInComp3];
		
		boolean bPositive = !decValue.isNegative();
		String cs = Comp3Support.encodeDecComp3(decValue, m_nNbDigits-m_nNbDecimals, m_nNbDecimals);
		Comp3Support.internalWriteEncodeComp3(aBytes, cs, bPositive, true);
					
		//m_nPhysicalPosInRecordSet += nNbCharsInComp3;
		return aBytes;					
	}
	catch (SQLException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:35,代码来源:DbColDefinitionDecimal.java

示例4: getByteValue

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public byte[] getByteValue(ResultSet resultSet, int nCol1Based, boolean bEbcdicOutput)
{
	try
	{
		String csValue = resultSet.getString(nCol1Based);
		
		ResultSetMetaData rsMetaData = resultSet.getMetaData();

		int nColWidth = rsMetaData.getPrecision(nCol1Based);
		int nValueLength = csValue.length();
		
		byte[] aBytes = new byte[2 + nColWidth];
		Asserter.assertIfFalse(nColWidth == m_nLength);
		
		LittleEndingUnsignBinaryBufferStorage.writeUnsignedShort(aBytes, nValueLength, 0);
		
		byte[] aBytesValue = csValue.getBytes();
		if(bEbcdicOutput)	// Must outout in ebcdic
			AsciiEbcdicConverter.swapByteAsciiToEbcdic(aBytesValue, 0, nValueLength);
		
		int n=0, nDest=2;
		for(; n<aBytesValue.length; n++, nDest++)
		{
			aBytes[nDest] = aBytesValue[n];
		}
		
		while(n < nColWidth)
		{
			aBytes[nDest++] = 0;
			n++;
		}
		return aBytes;
	}
	catch (SQLException e)
	{
		return null;		
	}
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:39,代码来源:DbColDefinitionVarchar.java

示例5: mapRow

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
@Override
public Map<String, Object>  mapRow(ResultSet rs, int rowNum) throws SQLException {
	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Map mapOfColValues = createColumnMap(columnCount);
	for (int i = 1; i <= columnCount; i++) {
		String key = getColumnKey(JdbcUtils.lookupColumnName(rsmd, i));
		key = key.toLowerCase();
		Object obj = null;
		String typename= rsmd.getColumnTypeName(i);
		if("NUMBER".equals(typename)){
			int scale = rsmd.getScale(i);
			int precision = rsmd.getPrecision(i);
			if(scale == 0){
				if(precision<10)
					obj = rs.getInt(i);
				else
					obj = rs.getLong(i);
			}else if(scale>0){
				obj = rs.getDouble(i);
			}else
				obj = rs.getLong(i);
		}else{
			obj = getColumnValue(rs, i);
		}

		mapOfColValues.put(key, obj);
	}
	return mapOfColValues;
}
 
开发者ID:yulele166,项目名称:pub-service,代码行数:31,代码来源:OracleColumnMapRowMapper.java

示例6: setup

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
@Override
public void setup(OperatorContext operatorContext, OutputMutator output) throws ExecutionSetupException {
  try {

    this.operatorContext = operatorContext;
    connection = source.getConnection();
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);

    final ResultSetMetaData meta = resultSet.getMetaData();
    final int columns = meta.getColumnCount();
    ImmutableList.Builder<ValueVector> vectorBuilder = ImmutableList.builder();
    ImmutableList.Builder<Copier<?>> copierBuilder = ImmutableList.builder();

    for (int i = 1; i <= columns; i++) {
      final String name = meta.getColumnLabel(i);
      final int jdbcType = meta.getColumnType(i);
      final int width = meta.getPrecision(i);
      final int scale = meta.getScale(i);
      MinorType minorType = JDBC_TYPE_MAPPINGS.get(jdbcType);
      if (minorType == null) {
        throw UserException.dataReadError()
            .message("The JDBC storage plugin failed while trying to execute a query. "
                + "The JDBC data type %d is not currently supported.", jdbcType)

            .addContext("sql", sql)
            .addContext("plugin", storagePluginName)
            .build(logger);
      }

      final MajorType type = Types.optional(minorType);
      final MaterializedField field = MaterializedField.create(name, type);
      final Class<? extends ValueVector> clazz = (Class<? extends ValueVector>) TypeHelper.getValueVectorClass(
          minorType, type.getMode());
      ValueVector vector = output.addField(field, clazz);
      vectorBuilder.add(vector);
      copierBuilder.add(getCopier(jdbcType, i, resultSet, vector));

    }

    vectors = vectorBuilder.build();
    copiers = copierBuilder.build();

  } catch (SQLException | SchemaChangeException e) {
    throw UserException.dataReadError(e)
        .message("The JDBC storage plugin failed while trying setup the SQL query. ")
        .addContext("sql", sql)
        .addContext("plugin", storagePluginName)
        .build(logger);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:52,代码来源:JdbcRecordReader.java

示例7: validateResultSet

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private MultiShardException validateResultSet(ResultSet r,
        ShardLocation loc) throws SQLException {
    if (r.isClosed()) {
        // ResultSet is already closed. Hence adding an exception in its place.
        return new MultiShardException(loc, new MultiShardResultSetClosedException(
                String.format("The result set for '%1$s' was closed and could not be added.", loc.getDatabase())));
    }
    ResultSetMetaData m = r.getMetaData();
    if (m == null || m.getColumnCount() == 0) {
        // ResultSet does not have proper metadata to read.
        return new MultiShardException(loc, new MultiShardResultSetInternalException(
                String.format("The result set for '%1$s' does not have proper metadata to read and could not be added.", loc.getDatabase())));
    }
    if (this.schemaComparisonTemplate == null) {
        this.schemaComparisonTemplate = r.getMetaData();
        return null;
    }
    for (int i = 1; i <= m.getColumnCount(); i++) {
        // Get the designated column's name.
        String expectedName = this.schemaComparisonTemplate.getColumnName(i);
        String actualName = m.getColumnName(i);
        if (!Objects.equals(expectedName, actualName)) {
            return new MultiShardException(loc, new MultiShardSchemaMismatchException(loc,
                    String.format("Expected schema column name %1$s, but encountered schema column name %2$s.", expectedName, actualName)));
        }

        // Retrieves the designated column's SQL type.
        if (!Objects.equals(this.schemaComparisonTemplate.getColumnType(i), m.getColumnType(i))) {
            return new MultiShardException(loc,
                    new MultiShardSchemaMismatchException(loc,
                            String.format("Mismatched SQL type values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
                                    this.schemaComparisonTemplate.getColumnTypeName(i), m.getColumnTypeName(i))));
        }

        // Get the designated column's specified column size.
        int expectedPrecision = this.schemaComparisonTemplate.getPrecision(i);
        int actualPrecision = m.getPrecision(i);
        if (!Objects.equals(expectedPrecision, actualPrecision)) {
            return new MultiShardException(loc,
                    new MultiShardSchemaMismatchException(loc,
                            String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
                                    expectedPrecision, actualPrecision)));
        }

        // Indicates the nullability of values in the designated column.
        int expectedNullableValue = this.schemaComparisonTemplate.isNullable(i);
        int actualNullableValue = m.isNullable(i);
        if (!Objects.equals(expectedNullableValue, actualNullableValue)) {
            return new MultiShardException(loc,
                    new MultiShardSchemaMismatchException(loc,
                            String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
                                    NullableValue.forValue(expectedNullableValue), NullableValue.forValue(actualNullableValue))));
        }
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:elastic-db-tools-for-java,代码行数:57,代码来源:MultiShardStatement.java

示例8: findMultiColumnInfos

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public List<ColumnInfo> findMultiColumnInfos(String dbInfoId, String sql) throws Exception {
	if (!StringUtils.hasText(sql)) {
		return null;
	}
	DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
	Connection conn = null;
	Statement st = null;
	ResultSet rs = null;
	try {
		conn = DataSourceUtils.getConnection(ds);
		st = conn.createStatement();
		rs = st.executeQuery(sql);
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		List<ColumnInfo> columnNames = new ArrayList<ColumnInfo>();
		ColumnInfo columnInfo = null;
		for (int i = 1; i <= count; i++) {
			columnInfo = new ColumnInfo();
			columnInfo.setColumnName(rsmd.getColumnLabel(i));
			columnInfo.setColumnType(rsmd.getColumnTypeName(i));
			columnInfo.setTableName(rsmd.getTableName(i));
			if (rsmd.getPrecision(i) > 0 && !columnInfo.getColumnType().equals("DATETIME") && !columnInfo.getColumnType().equals("TIMESTAMP") && !columnInfo.getColumnType().equals("DATE")) {
				columnInfo.setColumnSize(String.valueOf(rsmd.getPrecision(i)));
			}
			if (rsmd.getScale(i) > 0 && !columnInfo.getColumnType().equals("DATETIME") && !columnInfo.getColumnType().equals("TIMESTAMP") && !columnInfo.getColumnType().equals("DATE")) {
				columnInfo.setColumnSize(columnInfo.getColumnSize() + "," + rsmd.getScale(i));
			}
			int flagI = rsmd.isNullable(i);
			if (flagI == 0) {
				columnInfo.setIsnullAble(false);
			} else {
				columnInfo.setIsnullAble(true);
			}
			columnNames.add(columnInfo);
		}
		return columnNames;
	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(st);
		JdbcUtils.closeConnection(conn);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:43,代码来源:DbCommonServiceImpl.java


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