當前位置: 首頁>>代碼示例>>Java>>正文


Java ResultSetMetaData.getScale方法代碼示例

本文整理匯總了Java中java.sql.ResultSetMetaData.getScale方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSetMetaData.getScale方法的具體用法?Java ResultSetMetaData.getScale怎麽用?Java ResultSetMetaData.getScale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.ResultSetMetaData的用法示例。


在下文中一共展示了ResultSetMetaData.getScale方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isEqualsTo

import java.sql.ResultSetMetaData; //導入方法依賴的package包/類
boolean isEqualsTo(ResultSetMetaData metadata, int colNum) throws SQLException {
  return
      metadata.getCatalogName(colNum).equals(InfoSchemaConstants.IS_CATALOG_NAME) &&
      metadata.getSchemaName(colNum).isEmpty() &&
      metadata.getTableName(colNum).isEmpty() &&
      metadata.getColumnName(colNum).equals(columnName) &&
      metadata.getColumnLabel(colNum).equals(columnName) &&
      metadata.getColumnType(colNum) == type &&
      metadata.isNullable(colNum) == nullable &&
      // There is an existing bug where query results doesn't contain the precision for VARCHAR field.
      //metadata.getPrecision(colNum) == precision &&
      metadata.getScale(colNum) == scale &&
      metadata.isSigned(colNum) == signed &&
      metadata.getColumnDisplaySize(colNum) == displaySize &&
      metadata.getColumnClassName(colNum).equals(className) &&
      metadata.isSearchable(colNum) &&
      metadata.isAutoIncrement(colNum) == false &&
      metadata.isCaseSensitive(colNum) == false &&
      metadata.isReadOnly(colNum) &&
      metadata.isWritable(colNum) == false &&
      metadata.isDefinitelyWritable(colNum) == false &&
      metadata.isCurrency(colNum) == false;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:24,代碼來源:PreparedStatementTest.java

示例2: resultSetToFieldPacket

import java.sql.ResultSetMetaData; //導入方法依賴的package包/類
public static void resultSetToFieldPacket(String charset,
										  List<FieldPacket> fieldPks, ResultSet rs,
										  boolean isSpark) throws SQLException {
	ResultSetMetaData metaData = rs.getMetaData();
	int colunmCount = metaData.getColumnCount();
	if (colunmCount > 0) {
		//String values="";
		for (int i = 0; i < colunmCount; i++) {
			int j = i + 1;
			FieldPacket fieldPacket = new FieldPacket();
			fieldPacket.orgName = StringUtil.encode(metaData.getColumnName(j),charset);
			fieldPacket.name = StringUtil.encode(metaData.getColumnLabel(j), charset);
			if (! isSpark){
			  fieldPacket.orgTable = StringUtil.encode(metaData.getTableName(j), charset);
			  fieldPacket.table = StringUtil.encode(metaData.getTableName(j),	charset);
			  fieldPacket.db = StringUtil.encode(metaData.getSchemaName(j),charset);
			  fieldPacket.flags = toFlag(metaData, j);
			}
			fieldPacket.length = metaData.getColumnDisplaySize(j);
			
			fieldPacket.decimals = (byte) metaData.getScale(j);
			int javaType = MysqlDefs.javaTypeDetect(
					metaData.getColumnType(j), fieldPacket.decimals);
			fieldPacket.type = (byte) (MysqlDefs.javaTypeMysql(javaType) & 0xff);
			if(MysqlDefs.isBianry((byte) fieldPacket.type)) {
				// 63 represent binary character set
				fieldPacket.charsetIndex = 63;
			}
			fieldPks.add(fieldPacket);
			//values+=metaData.getColumnLabel(j)+"|"+metaData.getColumnName(j)+"  ";
		}
		// System.out.println(values);
	}


}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:37,代碼來源:ResultSetUtil.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例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.getScale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。