List of usage examples for java.sql Types DOUBLE
int DOUBLE
To view the source code for java.sql Types DOUBLE.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE
.
From source file:net.chrisrichardson.bankingExample.domain.jdbc.JdbcAccountDao.java
public void saveAccount(Account account) { int count = jdbcTemplate.update( "UPDATE BANK_ACCOUNT set accountId = ?, BALANCE = ?, overdraftPolicy = ?, dateOpened = ?, requiredYearsOpen = ?, limit = ? WHERE ACCOUNT_ID = ?", new Object[] { account.getAccountId(), account.getBalance(), account.getOverdraftPolicy(), new Timestamp(account.getDateOpened().getTime()), account.getRequiredYearsOpen(), account.getLimit(), account.getId() }, new int[] { Types.VARCHAR, Types.DOUBLE, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE, Types.INTEGER }); Assert.isTrue(count == 1);/*from w w w . j a va 2 s .c o m*/ }
From source file:org.apache.kylin.jdbc.KylinClient.java
@SuppressWarnings("rawtypes") public static Class convertType(int sqlType) { Class result = Object.class; switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: result = String.class; break;/*from w ww .j a v a2s . com*/ case Types.NUMERIC: case Types.DECIMAL: result = BigDecimal.class; break; case Types.BIT: result = Boolean.class; break; case Types.TINYINT: result = Byte.class; break; case Types.SMALLINT: result = Short.class; break; case Types.INTEGER: result = Integer.class; break; case Types.BIGINT: result = Long.class; break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: result = Double.class; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: result = Byte[].class; break; case Types.DATE: result = Date.class; break; case Types.TIME: result = Time.class; break; case Types.TIMESTAMP: result = Timestamp.class; break; default: //do nothing break; } return result; }
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 ww w . j ava2 s . c om*/ 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:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java
/** * Creates a new platform instance.//from w w w . j ava 2 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:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java
/** * ? ?//from w w w . j av a2 s .c o m * * @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; }
From source file:com.btobits.automator.ant.sql.task.SQLCompareTask.java
private void verify() throws Exception { final LinkedList<SQLCompareTask.VerifyCell> rows = impl.getVerifySqls(); for (final SQLCompareTask.VerifyCell sqlRow : rows) { sqlRow.validate();/*from ww w . j a v a2s.co m*/ switch (getColumnType(sqlRow)) { case Types.DOUBLE: { final Double val = (Double) getRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final DoubleValidator doubleValidator = new DoubleValidator(); if (doubleValidator.isValid(sqlRow.getValue())) { final Double dbValue = doubleValidator.validate(sqlRow.getValue()); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Double value."); } } break; case Types.FLOAT: { final Float val = (Float) getRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final FloatValidator validator = new FloatValidator(); if (validator.isValid(sqlRow.getValue())) { final Float dbValue = validator.validate(sqlRow.getValue()); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Float value."); } } break; case Types.DECIMAL: { final BigDecimal val = (BigDecimal) getRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final BigDecimalValidator validator = new BigDecimalValidator(); if (validator.isValid(sqlRow.getValue())) { BigDecimal dbValue = validator.validate(sqlRow.getValue()); dbValue = dbValue.setScale(val.scale()); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Decimal value."); } } break; case Types.DATE: { final Date val = (Date) getDateRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final DateValidator validator = DateValidator.getInstance(); if (validator.isValid(sqlRow.getValue(), "yyyy-MM-dd")) { final Date dbValue = validator.validate(sqlRow.getValue(), "yyyy-MM-dd"); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Date value."); } } break; case Types.TIME: { final Date val = (Date) getTimeRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final TimeValidator validator = TimeValidator.getInstance(); if (validator.isValid(sqlRow.getValue(), "HH:mm:ss")) { final Calendar dbValue = validator.validate(sqlRow.getValue(), "HH:mm:ss"); final Calendar dbVal = Calendar.getInstance(); dbVal.setTime(val); if (validator.compareHours(dbValue, dbVal) != 0 || validator.compareMinutes(dbValue, dbVal) != 0 || validator.compareSeconds(dbValue, dbVal) != 0) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Time value."); } } break; case Types.TIMESTAMP: { final Date val = getDateTimeRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final CalendarValidator validatorDate = CalendarValidator.getInstance(); final TimeValidator validatorTime = TimeValidator.getInstance(); if (validatorDate.isValid(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss")) { final Calendar dbValue = validatorDate.validate(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss"); final Calendar dbVal = Calendar.getInstance(); dbVal.setTimeInMillis(val.getTime()); if (validatorDate.compareDates(dbVal, dbValue) != 0 || validatorTime.compareHours(dbValue, dbVal) != 0 || validatorTime.compareMinutes(dbValue, dbVal) != 0 || validatorTime.compareSeconds(dbValue, dbVal) != 0) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Timestamp value."); } } break; default: { final String dbValue = getStringRowValue(sqlRow); if (dbValue == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } else if (!StringUtils.equals(sqlRow.getValue(), dbValue)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + dbValue + "]"); } } } } }
From source file:com.sangupta.fileanalysis.db.DBResultViewer.java
/** * View resutls of a {@link ResultSet}.// w w w .java 2 s.c om * * @param resultSet * @throws SQLException */ public void viewResult(ResultSet resultSet) throws SQLException { if (resultSet == null) { // nothing to do return; } // collect the meta ResultSetMetaData meta = resultSet.getMetaData(); final int numColumns = meta.getColumnCount(); final int[] displaySizes = new int[numColumns + 1]; final int[] colType = new int[numColumns + 1]; for (int index = 1; index <= numColumns; index++) { colType[index] = meta.getColumnType(index); displaySizes[index] = getColumnSize(meta.getTableName(index), meta.getColumnName(index), colType[index]); } // display the header row for (int index = 1; index <= numColumns; index++) { center(meta.getColumnLabel(index), displaySizes[index]); } System.out.println("|"); for (int index = 1; index <= numColumns; index++) { System.out.print("+" + StringUtils.repeat('-', displaySizes[index] + 2)); } System.out.println("+"); // start iterating over the result set int rowsDisplayed = 0; int numRecords = 0; while (resultSet.next()) { // read and display the value rowsDisplayed++; numRecords++; for (int index = 1; index <= numColumns; index++) { switch (colType[index]) { case Types.DECIMAL: case Types.DOUBLE: case Types.REAL: format(resultSet.getDouble(index), displaySizes[index]); continue; case Types.INTEGER: case Types.SMALLINT: format(resultSet.getInt(index), displaySizes[index]); continue; case Types.VARCHAR: format(resultSet.getString(index), displaySizes[index], false); continue; case Types.TIMESTAMP: format(resultSet.getTimestamp(index), displaySizes[index]); continue; case Types.BIGINT: format(resultSet.getBigDecimal(index), displaySizes[index]); continue; } } // terminator for row and new line System.out.println("|"); // check for rows displayed if (rowsDisplayed == 20) { // ask the user if more data needs to be displayed String cont = ConsoleUtils.readLine("Type \"it\" for more: ", true); if (!"it".equalsIgnoreCase(cont)) { break; } // continue; rowsDisplayed = 0; continue; } } System.out.println("\nTotal number of records found: " + numRecords); }
From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits.//from w ww. j a va 2s . c om */ 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:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING:/* w w w.j a va2s . c o m*/ if (type.isUnconstrained()) { return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR); } else if (type.isClob() || type.length > 2000) { return jdbcInfo("NCLOB", Types.CLOB); } else { return jdbcInfo("NVARCHAR2(%d)", type.length, Types.VARCHAR); } case BOOLEAN: return jdbcInfo("NUMBER(1,0)", Types.BIT); case LONG: return jdbcInfo("NUMBER(19,0)", Types.BIGINT); case DOUBLE: return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("TIMESTAMP", Types.TIMESTAMP); case BLOBID: return jdbcInfo("VARCHAR2(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: return jdbcInfo("VARCHAR2(36)", Types.VARCHAR); case SYSNAME: case SYSNAMEARRAY: return jdbcInfo("VARCHAR2(250)", Types.VARCHAR); case TINYINT: return jdbcInfo("NUMBER(3,0)", Types.TINYINT); case INTEGER: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case FTINDEXED: return jdbcInfo("CLOB", Types.CLOB); case FTSTORED: return jdbcInfo("NCLOB", Types.CLOB); case CLUSTERNODE: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectOracle.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type) { case VARCHAR: return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR); case CLOB://from w w w . j a va 2 s . com return jdbcInfo("NCLOB", Types.CLOB); case BOOLEAN: return jdbcInfo("NUMBER(1,0)", Types.BIT); case LONG: return jdbcInfo("NUMBER(19,0)", Types.BIGINT); case DOUBLE: return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("TIMESTAMP", Types.TIMESTAMP); case BLOBID: return jdbcInfo("VARCHAR2(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEVAL: return jdbcInfo("VARCHAR2(36)", Types.VARCHAR); case SYSNAME: return jdbcInfo("VARCHAR2(250)", Types.VARCHAR); case TINYINT: return jdbcInfo("NUMBER(3,0)", Types.TINYINT); case INTEGER: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case FTINDEXED: return jdbcInfo("CLOB", Types.CLOB); case FTSTORED: return jdbcInfo("NCLOB", Types.CLOB); case CLUSTERNODE: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR); } throw new AssertionError(type); }