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:org.apache.ddlutils.platform.oracle.Oracle8ModelReader.java
/** * {@inheritDoc}// w w w. j av a2 s . c o m */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getDefaultValue() != null) { // Oracle pads the default value with spaces column.setDefaultValue(column.getDefaultValue().trim()); } if (column.getTypeCode() == Types.DECIMAL) { // We're back-mapping the NUMBER columns returned by Oracle // Note that the JDBC driver returns DECIMAL for these NUMBER columns switch (column.getSizeAsInt()) { case 1: if (column.getScale() == 0) { column.setTypeCode(Types.BIT); } break; case 3: if (column.getScale() == 0) { column.setTypeCode(Types.TINYINT); } break; case 5: if (column.getScale() == 0) { column.setTypeCode(Types.SMALLINT); } break; case 18: column.setTypeCode(Types.REAL); break; case 22: if (column.getScale() == 0) { column.setTypeCode(Types.INTEGER); } break; case 38: if (column.getScale() == 0) { column.setTypeCode(Types.BIGINT); } else { column.setTypeCode(Types.DOUBLE); } break; } } else if (column.getTypeCode() == Types.FLOAT) { // Same for REAL, FLOAT, DOUBLE PRECISION, which all back-map to FLOAT but with // different sizes (63 for REAL, 126 for FLOAT/DOUBLE PRECISION) switch (column.getSizeAsInt()) { case 63: column.setTypeCode(Types.REAL); break; case 126: column.setTypeCode(Types.DOUBLE); break; } } else if ((column.getTypeCode() == Types.DATE) || (column.getTypeCode() == Types.TIMESTAMP)) { // Oracle has only one DATE/TIME type, so we can't know which it is and thus map // it back to TIMESTAMP column.setTypeCode(Types.TIMESTAMP); // we also reverse the ISO-format adaptation, and adjust the default value to timestamp if (column.getDefaultValue() != null) { Matcher matcher = _oracleIsoTimestampPattern.matcher(column.getDefaultValue()); Timestamp timestamp = null; if (matcher.matches()) { String timestampVal = matcher.group(1); timestamp = Timestamp.valueOf(timestampVal); } else { matcher = _oracleIsoDatePattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String dateVal = matcher.group(1); timestamp = new Timestamp(Date.valueOf(dateVal).getTime()); } else { matcher = _oracleIsoTimePattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String timeVal = matcher.group(1); timestamp = new Timestamp(Time.valueOf(timeVal).getTime()); } } } if (timestamp != null) { column.setDefaultValue(timestamp.toString()); } } } else if (TypeMap.isTextType(column.getTypeCode())) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); } return column; }
From source file:org.easyrec.plugin.arm.store.dao.impl.RuleminingItemAssocDAOMysqlImpl.java
@Override public int insertOrUpdateItemAssoc(ItemAssocVO<Integer, Integer> itemAssoc) { // validate input parameters if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); }/*from www. j a v a 2 s .c o m*/ // validate unique key validateUniqueKey(itemAssoc); validateAssocValue(itemAssoc); validateViewType(itemAssoc); if (logger.isDebugEnabled()) { logger.debug("inserting 'itemAssoc': " + itemAssoc); } // @HINT: maybe use UniqueIdService later (instead of auto_imcrement) StringBuilder sqlString = new StringBuilder("INSERT INTO "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" ("); sqlString.append(DEFAULT_TENANT_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append(", "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append(", "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); if (itemAssoc.getChangeDate() == null) { itemAssoc.setChangeDate(new Date(System.currentTimeMillis())); } if (itemAssoc.isActive() != null) { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } else { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } sqlString.append(" ON DUPLICATE KEY UPDATE "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME); sqlString.append("=?, "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append("=?, "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); sqlString.append("=?"); Object[] args; int[] argTypes; if (itemAssoc.isActive() != null) { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.isActive(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.isActive(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.BOOLEAN, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.BOOLEAN, Types.TIMESTAMP, }; } else { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, }; } PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(sqlString.toString(), argTypes); int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args)); return rowsAffected; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: setToPreparedStatementString(ps, index, value, column); return;/*w w w . ja va2 s. c o m*/ case Types.BIT: ps.setInt(index, ((Boolean) value).booleanValue() ? 1 : 0); return; case Types.TINYINT: case Types.SMALLINT: ps.setInt(index, ((Long) value).intValue()); return; case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Number) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: setToPreparedStatementTimestamp(ps, index, value, column); return; default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
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;// w w w . j a v a 2s .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.easyrec.plugin.profileduke.store.dao.impl.ProfileSimilarityItemAssocDAOMysqlImpl.java
public int insertOrUpdateItemAssoc(ItemAssocVO<Integer, Integer> itemAssoc) { // validate input parameters if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); }/* w w w . jav a 2 s . c om*/ // validate unique key validateUniqueKey(itemAssoc); validateAssocValue(itemAssoc); validateViewType(itemAssoc); if (logger.isDebugEnabled()) { logger.debug("inserting 'itemAssoc': " + itemAssoc); } // @HINT: maybe use UniqueIdService later (instead of auto_imcrement) StringBuilder sqlString = new StringBuilder("INSERT INTO "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" ("); sqlString.append(DEFAULT_TENANT_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append(", "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append(", "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); if (itemAssoc.getChangeDate() == null) { itemAssoc.setChangeDate(new Date(System.currentTimeMillis())); } if (itemAssoc.isActive() != null) { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } else { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } sqlString.append(" ON DUPLICATE KEY UPDATE "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME); sqlString.append("=?, "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append("=?, "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); sqlString.append("=?"); Object[] args; int[] argTypes; if (itemAssoc.isActive() != null) { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.isActive(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.isActive(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.BOOLEAN, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.BOOLEAN, Types.TIMESTAMP, }; } else { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, }; } PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(sqlString.toString(), argTypes); int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args)); return rowsAffected; }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize) { // Oracle internal conversions if (expected == Types.DOUBLE && actual == Types.FLOAT) { return true; }// ww w . ja v a 2s . c o m if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.BIT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 1) { return true; } if (expected == Types.TINYINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 3) { return true; } if (expected == Types.INTEGER && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 10) { return true; } if (expected == Types.BIGINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 19) { return true; } // CLOB vs VARCHAR compatibility if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } return false; }
From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java
private static Class<?> getJavaType(int sqltype, int precision, int scale) { switch (sqltype) { case Types.BIGINT: return Long.class; case Types.BIT: return Boolean.class; case Types.BOOLEAN: return Boolean.class; case Types.CHAR: return String.class; case Types.DECIMAL: return getNumericType(precision, scale); case Types.DOUBLE: return Double.class; case Types.FLOAT: return Double.class; case Types.INTEGER: return Integer.class; case Types.LONGVARCHAR: return String.class; case Types.NUMERIC: return getNumericType(precision, scale); case Types.REAL: return Float.class; case Types.SMALLINT: return Short.class; case Types.DATE: return java.sql.Timestamp.class; case Types.TIME: return java.sql.Time.class; case Types.TIMESTAMP: return java.sql.Timestamp.class; case Types.TINYINT: return Byte.class; case Types.VARCHAR: return String.class; case Types.BLOB: return byte[].class; case Types.LONGVARBINARY: return byte[].class; case Types.CLOB: return String.class; case Types.BINARY: return byte[].class; case Types.VARBINARY: return byte[].class; case Types.NVARCHAR: return String.class; case Types.NCHAR: return String.class; case Types.LONGNVARCHAR: return String.class; case -155:// ww w . java 2 s . c om return java.sql.Timestamp.class; default: return Object.class; } }
From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java
protected void registerDefaultJavaTypes() { registerJavaType(Types.BIT, Boolean.class.getName()); registerJavaType(Types.TINYINT, Byte.class.getName()); registerJavaType(Types.SMALLINT, Short.class.getName()); // registerJavaType(Types.CHAR, Character.class.getName()); registerJavaType(Types.CHAR, String.class.getName()); registerJavaType(Types.VARCHAR, String.class.getName()); registerJavaType(Types.DATE, Date.class.getName()); registerJavaType(Types.TIME, Time.class.getName()); registerJavaType(Types.TIMESTAMP, Timestamp.class.getName()); registerJavaType(Types.DOUBLE, Double.class.getName()); registerJavaType(Types.FLOAT, Float.class.getName()); registerJavaType(Types.INTEGER, Integer.class.getName()); registerJavaType(Types.BIGINT, BigInteger.class.getName()); // registerJavaType(Types.BIGINT, Long.class.getName()); registerJavaType(Types.NUMERIC, BigDecimal.class.getName()); registerJavaType(Types.DECIMAL, BigDecimal.class.getName()); registerJavaType(Types.BINARY, byte[].class.getName()); registerJavaType(Types.VARBINARY, byte[].class.getName()); registerJavaType(Types.BLOB, String.class.getName()); registerJavaType(Types.CLOB, String.class.getName()); registerJavaType(Types.REAL, String.class.getName()); registerJavaType(Types.OTHER, Object.class.getName()); }
From source file:org.apache.ddlutils.platform.JdbcModelReader.java
/** * Creates a new model reader instance.//from w w w . j a v a2 s . c om * * @param platform The plaftform this builder belongs to */ public JdbcModelReader(Platform platform) { _platform = platform; _defaultSizes.put(new Integer(Types.CHAR), "254"); _defaultSizes.put(new Integer(Types.VARCHAR), "254"); _defaultSizes.put(new Integer(Types.LONGVARCHAR), "254"); _defaultSizes.put(new Integer(Types.BINARY), "254"); _defaultSizes.put(new Integer(Types.VARBINARY), "254"); _defaultSizes.put(new Integer(Types.LONGVARBINARY), "254"); _defaultSizes.put(new Integer(Types.INTEGER), "32"); _defaultSizes.put(new Integer(Types.BIGINT), "64"); _defaultSizes.put(new Integer(Types.REAL), "7,0"); _defaultSizes.put(new Integer(Types.FLOAT), "15,0"); _defaultSizes.put(new Integer(Types.DOUBLE), "15,0"); _defaultSizes.put(new Integer(Types.DECIMAL), "15,15"); _defaultSizes.put(new Integer(Types.NUMERIC), "15,15"); _columnsForTable = initColumnsForTable(); _columnsForColumn = initColumnsForColumn(); _columnsForPK = initColumnsForPK(); _columnsForFK = initColumnsForFK(); _columnsForIndex = initColumnsForIndex(); }