當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。