本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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) + '\'' +
']';
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}