List of usage examples for java.sql Types DECIMAL
int DECIMAL
To view the source code for java.sql Types DECIMAL.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DECIMAL
.
From source file:com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits.//from w w w .j av a 2s. co m */ protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }
From source file:co.nubetech.apache.hadoop.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits./*w ww. j a v a2 s . c o m*/ */ protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, // BLOB, ARRAY // STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }
From source file:co.nubetech.hiho.mapreduce.lib.db.apache.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query into InputSplits. */// w w w . java 2 s. com protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY // STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }
From source file:wzw.sql.ResultSetConverter.java
/** * ?/* www . j a v a2 s. c o m*/ * @param rs * @param type Listjava.sql.Types * @return * @throws SQLException */ public static List<Object> toTypeList(ResultSet rs, int type) throws SQLException { List<Object> list = new ArrayList<Object>(); switch (type) { case Types.INTEGER: while (rs.next()) { list.add(new Integer(rs.getInt(1))); } case Types.BIGINT: while (rs.next()) { list.add(new Long(rs.getLong(1))); } case Types.VARCHAR: while (rs.next()) { list.add(rs.getString(1)); } case Types.FLOAT: while (rs.next()) { list.add(new Float(rs.getFloat(1))); } case Types.DECIMAL: case Types.DOUBLE: case Types.NUMERIC: while (rs.next()) { list.add(new Double(rs.getDouble(1))); } case Types.TIMESTAMP: while (rs.next()) { list.add(rs.getTimestamp(1)); } case Types.DATE: while (rs.next()) { list.add(rs.getDate(1)); } case Types.TIME: while (rs.next()) { list.add(rs.getTime(1)); } //default: } return list; }
From source file:org.efaps.db.wrapper.AbstractSQLInsertUpdate.java
/** * Defines a new column <code>_columnName</code> with {@link BigDecimal} * <code>_value</code> within this SQL insert / update statement. * * @param _columnName name of the column * @param _value value of the column * @return this SQL statement/*from w w w. j av a2s . c o m*/ */ @SuppressWarnings("unchecked") public STMT column(final String _columnName, final BigDecimal _value) { this.columnWithValues .add(new AbstractSQLInsertUpdate.AbstractColumnWithValue<BigDecimal>(_columnName, _value) { @Override public void set(final int _index, final PreparedStatement _stmt) throws SQLException { if (getValue() == null) { _stmt.setNull(_index, Types.DECIMAL); } else { _stmt.setBigDecimal(_index, getValue()); } } }); return (STMT) this; }
From source file:org.apache.tajo.storage.jdbc.JdbcMetadataProviderBase.java
private TypeDesc convertDataType(ResultSet res) throws SQLException { final int typeId = res.getInt("DATA_TYPE"); switch (typeId) { case Types.BOOLEAN: return new TypeDesc(newSimpleDataType(Type.BOOLEAN)); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return new TypeDesc(newSimpleDataType(Type.INT4)); case Types.DISTINCT: // sequence for postgresql case Types.BIGINT: return new TypeDesc(newSimpleDataType(Type.INT8)); case Types.FLOAT: return new TypeDesc(newSimpleDataType(Type.FLOAT4)); case Types.NUMERIC: case Types.DECIMAL: case Types.DOUBLE: return new TypeDesc(newSimpleDataType(Type.FLOAT8)); case Types.DATE: return new TypeDesc(newSimpleDataType(Type.DATE)); case Types.TIME: return new TypeDesc(newSimpleDataType(Type.TIME)); case Types.TIMESTAMP: return new TypeDesc(newSimpleDataType(Type.TIMESTAMP)); case Types.CHAR: case Types.NCHAR: case Types.VARCHAR: case Types.NVARCHAR: case Types.CLOB: case Types.NCLOB: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: return new TypeDesc(newSimpleDataType(Type.TEXT)); case Types.BINARY: case Types.VARBINARY: case Types.BLOB: return new TypeDesc(newSimpleDataType(Type.BLOB)); default:/* w ww.j a va 2 s. co m*/ throw SQLExceptionUtil.toSQLException(new UnsupportedDataTypeException(typeId + "")); } }
From source file:madgik.exareme.master.queryProcessor.analyzer.stat.Stat.java
private int computeColumnSize(String columnName, int columnType, String table_sample) throws Exception { int columnSize = 0; if (columnType == Types.INTEGER || columnType == Types.REAL || columnType == Types.DOUBLE || columnType == Types.DECIMAL || columnType == Types.FLOAT || columnType == Types.NUMERIC) { columnSize = NUM_SIZE;//from w w w .ja va 2 s .c o m } else if (columnType == Types.VARCHAR) { String query0 = "select max(length(`" + columnName + "`)) as length from (select `" + columnName + "` from `" + table_sample + "`)" + " where `" + columnName + "` is not null limit " + MAX_STRING_SAMPLE; Statement stmt0 = con.createStatement(); ResultSet rs0 = stmt0.executeQuery(query0); while (rs0.next()) { columnSize = rs0.getInt("length"); } rs0.close(); stmt0.close(); } else if (columnType == Types.BLOB) columnSize = BLOB_SIZE; return columnSize; }
From source file:com.opencsv.ResultSetHelperService.java
private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getObject(colIndex), ""); value = ObjectUtils.toString(rs.getObject(colIndex), ""); break;//from w ww . j a v a2s . com case Types.BOOLEAN: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getBoolean(colIndex)); value = ObjectUtils.toString(rs.getBoolean(colIndex)); break; case Types.NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { StrBuilder sb = new StrBuilder(); sb.readFrom(c.getCharacterStream()); value = sb.toString(); } break; case Types.BIGINT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getLong(colIndex)); value = ObjectUtils.toString(rs.getLong(colIndex)); break; case Types.DECIMAL: case Types.REAL: case Types.NUMERIC: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getBigDecimal(colIndex), ""); value = ObjectUtils.toString(rs.getBigDecimal(colIndex), ""); break; case Types.DOUBLE: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getDouble(colIndex)); value = ObjectUtils.toString(rs.getDouble(colIndex)); break; case Types.FLOAT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getFloat(colIndex)); value = ObjectUtils.toString(rs.getFloat(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getInt(colIndex)); value = ObjectUtils.toString(rs.getInt(colIndex)); break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { SimpleDateFormat df = new SimpleDateFormat(dateFormatString); value = df.format(date); } break; case Types.TIME: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getTime(colIndex), ""); value = ObjectUtils.toString(rs.getTime(colIndex), ""); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex), timestampFormatString); break; case Types.NVARCHAR: // todo : use rs.getNString case Types.NCHAR: // todo : use rs.getNString case Types.LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: String columnValue = rs.getString(colIndex); if (trim && columnValue != null) { value = columnValue.trim(); } else { value = columnValue; } break; default: value = ""; } if (rs.wasNull() || value == null) { value = ""; } return value; }
From source file:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java
/** * {@inheritDoc}/*from ww w .j a v a2s .c om*/ */ protected String getValueAsString(Column column, Object value) { if (value == null) { return "NULL"; } StringBuffer result = new StringBuffer(); switch (column.getTypeCode()) { case Types.REAL: case Types.NUMERIC: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: // SQL Server does not want quotes around the value if (!(value instanceof String) && (getValueNumberFormat() != null)) { result.append(getValueNumberFormat().format(value)); } else { result.append(value.toString()); } break; case Types.DATE: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value instanceof String ? (String) value : getValueDateFormat().format(value)); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; case Types.TIME: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value instanceof String ? (String) value : getValueTimeFormat().format(value)); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; case Types.TIMESTAMP: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value.toString()); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; } return super.getValueAsString(column, value); }