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:io.lightlink.oracle.AbstractOracleType.java
protected ARRAY createArray(Connection con, Object value, String typeName) throws SQLException { if (value == null) return null; ArrayDescriptor arrayStructDesc = safeCreateArrayDescriptor(typeName, con); if (value == null) return null; if (value.getClass().isArray()) { value = Arrays.asList((Object[]) value); }/*from www . ja v a 2 s . c o m*/ List records = (List) value; String baseName = arrayStructDesc.getBaseName(); int baseType = arrayStructDesc.getBaseType(); if (baseType == Types.VARCHAR || baseType == Types.CHAR || baseType == Types.CLOB || baseType == Types.NUMERIC || baseType == Types.INTEGER || baseType == Types.BIGINT || baseType == Types.FLOAT || baseType == Types.DOUBLE || baseType == Types.DECIMAL || baseType == Types.NCHAR || baseType == Types.NVARCHAR || baseType == Types.NCLOB) { return new ARRAY(arrayStructDesc, con, records.toArray()); // primitive array } else { Object[] structArray = new Object[records.size()]; for (int i = 0; i < structArray.length; i++) { Object record = records.get(i); if (baseType == OracleTypes.JAVA_STRUCT || baseType == OracleTypes.JAVA_OBJECT || baseType == OracleTypes.STRUCT || baseType == OracleTypes.JAVA_STRUCT) { record = createStruct(con, record, baseName); } else if (baseType == OracleTypes.ARRAY) { record = createArray(con, record, baseName); } structArray[i] = record; } return new ARRAY(arrayStructDesc, con, structArray); } }
From source file:org.castor.cpa.persistence.sql.keygen.MaxKeyGenerator.java
/** * Initialize the MAX key generator.// w ww . j a v a 2s . c o m * * @param factory A PersistenceFactory instance. * @param sqlType A SQLTypidentifier. * @throws MappingException if this key generator is not compatible with the * persistance factory. */ public MaxKeyGenerator(final PersistenceFactory factory, final int sqlType) throws MappingException { super(factory); _factory = factory; if ((sqlType != Types.INTEGER) && (sqlType != Types.BIGINT) && (sqlType != Types.NUMERIC) && (sqlType != Types.DECIMAL)) { String msg = Messages.format("mapping.keyGenSQLType", getClass().getName(), new Integer(sqlType)); throw new MappingException(msg); } initSqlTypeHandler(sqlType); }
From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java
public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException { String value = ""; switch (colType) { case Types.BIT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); }/*from ww w . j a v a 2 s.com*/ break; case Types.BOOLEAN: if (jdbcObject != null) { value = new Boolean(jdbcObject.toString()).toString(); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.CLOB: if (jdbcObject != null) { try { value = read((Clob) jdbcObject); } catch (SQLException sqle) { value = ""; } catch (IOException ioe) { value = ""; } } break; case Types.ARRAY: try { ResultSet rs = ((Array) jdbcObject).getResultSet(); int arrayType = ((Array) jdbcObject).getBaseType(); boolean isNotNew = false; while (rs.next()) { String current = formatJDBCObject(rs.getObject(2), arrayType); if ("".equals(current.trim()) == false) { if (isNotNew) { value = value + ","; } else { isNotNew = !isNotNew; } value = value + current; } } if ("".equals(value) == false) { value = "{" + value + "}"; } } catch (SQLException sqle) { value = ""; } break; case Types.JAVA_OBJECT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); } break; case Types.DATE: if (jdbcObject != null) { value = formatter.formatDate(jdbcObject); } break; case Types.TIME: if (jdbcObject != null) { value = ((Time) jdbcObject).toString(); } break; case Types.TIMESTAMP: if (jdbcObject != null) { value = formatter.formatTimestamp(jdbcObject); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: if (jdbcObject != null) { value = jdbcObject.toString(); } else { value = "NULL"; } break; case Types.BINARY: value = new String((byte[]) jdbcObject); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:org.castor.cpa.persistence.sql.keygen.TableKeyGenerator.java
private void assertNumericSqlType(final int sqlType) throws MappingException { switch (sqlType) { case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: case Types.DECIMAL: case Types.NUMERIC: break;// w w w .j a va 2 s .c o m default: String msg = Messages.format("mapping.keyGenSQLType", getClass().getName(), sqlType); throw new MappingException(msg); } }
From source file:wzw.sql.ResultSetConverter.java
/** * ?//from www.j a v a 2s . c o m * @param rs * @param type Listjava.sql.Types * @return * @throws SQLException */ public static Object toType(ResultSet rs, int type) throws SQLException { if (rs.next()) { // run rs.next() switch (type) { case Types.INTEGER: return new Integer(rs.getInt(1)); case Types.BIGINT: return new Long(rs.getLong(1)); case Types.VARCHAR: return rs.getString(1); case Types.FLOAT: return new Float(rs.getFloat(1)); case Types.DECIMAL: case Types.DOUBLE: case Types.NUMERIC: return new Double(rs.getDouble(1)); case Types.TIMESTAMP: return rs.getTimestamp(1); case Types.DATE: return rs.getDate(1); case Types.TIME: return rs.getTime(1); default: return null; } } return null; }
From source file:com.streamsets.pipeline.stage.it.AvroToParquetHiveIT.java
@Parameterized.Parameters(name = "type({0})") public static Collection<Object[]> data() throws Exception { return Arrays.asList(new Object[][] { // Primitive types { "\"boolean\"", true, true, "BOOLEAN", Types.BOOLEAN, "0" }, { "\"int\"", Integer.MIN_VALUE, Integer.MIN_VALUE, "INT", Types.INTEGER, "0" }, { "\"long\"", Long.MAX_VALUE, Long.MAX_VALUE, "BIGINT", Types.BIGINT, "0" }, // From some reason type is FLOAT, but returned object is double { "\"float\"", Float.NaN, Double.NaN, "FLOAT", Types.FLOAT, "0" }, { "\"double\"", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, "DOUBLE", Types.DOUBLE, "0" }, { "\"bytes\"", ByteBuffer.wrap(new byte[] { (byte) 0x00, (byte) 0xFF }), new byte[] { (byte) 0x00, (byte) 0xFF }, "BINARY", Types.BINARY, "1.0" }, { "\"string\"", new Utf8("StreamSets"), "StreamSets", "STRING", Types.VARCHAR, "1.0" }, // Complex types are skipped for now // Logical types { DECIMAL.toString(), ByteBuffer.wrap(new byte[] { (byte) 0x0F }), new BigDecimal("2"), "DECIMAL", Types.DECIMAL, "0" }, { DATE.toString(), 17039, new java.sql.Date(116, 7, 26), "DATE", Types.DATE, "1.2" }, }); }
From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java
/** * Creates a new platform instance./*from w ww.j a v a2 s . c o m*/ */ public PostgreSqlPlatform() { PlatformInfo info = getPlatformInfo(); info.setPrimaryKeyColumnAutomaticallyRequired(true); // this is the default length though it might be changed when building PostgreSQL // in file src/include/postgres_ext.h info.setMaxIdentifierLength(31); info.addNativeTypeMapping(Types.ARRAY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BINARY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BIT, "BOOLEAN"); info.addNativeTypeMapping(Types.BLOB, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "BOOLEAN", Types.BIT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DECIMAL, "NUMERIC", Types.NUMERIC); info.addNativeTypeMapping(Types.DISTINCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION"); info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE); info.addNativeTypeMapping(Types.JAVA_OBJECT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.NULL, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.VARBINARY, "BYTEA", Types.LONGVARBINARY); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); // no support for specifying the size for these types (because they are mapped // to BYTEA which back-maps to BLOB) info.setHasSize(Types.BINARY, false); info.setHasSize(Types.VARBINARY, false); setSqlBuilder(new PostgreSqlBuilder(this)); setModelReader(new PostgreSqlModelReader(this)); }
From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits.//ww w . ja va2 s . 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: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: 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:ResultsDecoratorSQL.java
public void write(ResultSet rs) throws IOException, SQLException { ResultSetMetaData md = rs.getMetaData(); // This assumes you're not using a Join!! String tableName = md.getTableName(1); int cols = md.getColumnCount(); StringBuffer sb = new StringBuffer("insert into ").append(tableName).append("("); for (int i = 1; i <= cols; i++) { sb.append(md.getColumnName(i));//from w w w.j av a 2 s .c o m if (i != cols) { sb.append(", "); } } sb.append(") values ("); String insertCommand = sb.toString(); while (rs.next()) { println(insertCommand); for (int i = 1; i <= cols; i++) { String tmp = rs.getString(i); if (rs.wasNull()) { print("null"); } else { int type = md.getColumnType(i); // Don't quote numeric types; quote all others for now. switch (type) { case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: print(tmp); break; default: tmp = tmp.replaceAll("'", "''"); print("'" + tmp + "'"); } } if (i != cols) { print(", "); } } println(");"); } }
From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java
/** * ? ?/* w ww . jav a2 s. c om*/ * * @param sqlType * @return */ public static boolean isNumberType(int sqlType) { switch (sqlType) { case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.NUMERIC: case Types.BIT: case Types.SMALLINT: case Types.TINYINT: return true; } return false; }