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:com.mapd.utility.SQLImporter.java
private String getColType(int cType, int precision, int scale) { if (precision > 19) { precision = 19;/*ww w.j a v a2 s . c om*/ } if (scale > 19) { scale = 18; } switch (cType) { case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: return ("SMALLINT"); case java.sql.Types.INTEGER: return ("INTEGER"); case java.sql.Types.BIGINT: return ("BIGINT"); case java.sql.Types.FLOAT: return ("FLOAT"); case java.sql.Types.DECIMAL: return ("DECIMAL(" + precision + "," + scale + ")"); case java.sql.Types.DOUBLE: return ("DOUBLE"); case java.sql.Types.REAL: return ("REAL"); case java.sql.Types.NUMERIC: return ("NUMERIC(" + precision + "," + scale + ")"); case java.sql.Types.TIME: return ("TIME"); case java.sql.Types.TIMESTAMP: return ("TIMESTAMP"); case java.sql.Types.DATE: return ("DATE"); case java.sql.Types.BOOLEAN: case java.sql.Types.BIT: // deal with postgress treating boolean as bit... this will bite me return ("BOOLEAN"); case java.sql.Types.NVARCHAR: case java.sql.Types.VARCHAR: case java.sql.Types.NCHAR: case java.sql.Types.CHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.LONGNVARCHAR: return ("TEXT ENCODING DICT"); default: throw new AssertionError("Column type " + cType + " not Supported"); } }
From source file:org.easyrec.store.dao.core.impl.ItemAssocDAOMysqlImpl.java
/** * updates an item association entry in the database, uses the primary key to retrieve the entry * only changes columns:<br/>/*from w ww . j av a 2s . c om*/ * - assocValue<br/> * - viewType<br/> * - changeDate<br/> */ @Override public int updateItemAssocUsingPrimaryKey(ItemAssocVO<Integer, Integer> itemAssoc) { // validate input parameters if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); } validatePrimaryKey(itemAssoc); validateAssocValue(itemAssoc); validateViewType(itemAssoc); if (logger.isDebugEnabled()) { logger.debug("updating 'itemAssoc' by primary key: " + itemAssoc); } StringBuilder sqlString; sqlString = new StringBuilder("UPDATE "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" SET "); sqlString.append(DEFAULT_ASSOC_VALUE_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())); } sqlString.append("=? WHERE "); sqlString.append(DEFAULT_ID_COLUMN_NAME); sqlString.append("=?"); Object[] args; int[] argTypes; if (itemAssoc.isActive() != null) { args = new Object[] { itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.isActive(), itemAssoc.getChangeDate(), itemAssoc.getId() }; argTypes = new int[] { Types.DOUBLE, Types.INTEGER, Types.BOOLEAN, Types.TIMESTAMP, Types.INTEGER }; } else { args = new Object[] { itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getChangeDate(), itemAssoc.getId() }; argTypes = new int[] { Types.DOUBLE, Types.INTEGER, Types.TIMESTAMP, Types.INTEGER }; } return getJdbcTemplate().update(sqlString.toString(), args, argTypes); }
From source file:com.liferay.portal.upgrade.util.Table.java
public void setColumn(PreparedStatement ps, int index, Integer type, String value) throws Exception { int t = type.intValue(); int paramIndex = index + 1; if (t == Types.BIGINT) { ps.setLong(paramIndex, GetterUtil.getLong(value)); } else if (t == Types.BOOLEAN) { ps.setBoolean(paramIndex, GetterUtil.getBoolean(value)); } else if ((t == Types.CLOB) || (t == Types.VARCHAR)) { value = StringUtil.replace(value, SAFE_CHARS[1], SAFE_CHARS[0]); ps.setString(paramIndex, value); } else if (t == Types.DOUBLE) { ps.setDouble(paramIndex, GetterUtil.getDouble(value)); } else if (t == Types.FLOAT) { ps.setFloat(paramIndex, GetterUtil.getFloat(value)); } else if (t == Types.INTEGER) { ps.setInt(paramIndex, GetterUtil.getInteger(value)); } else if (t == Types.SMALLINT) { ps.setShort(paramIndex, GetterUtil.getShort(value)); } else if (t == Types.TIMESTAMP) { if (StringPool.NULL.equals(value)) { ps.setTimestamp(paramIndex, null); } else {//from www . j av a 2 s. co m DateFormat df = DateUtil.getISOFormat(); ps.setTimestamp(paramIndex, new Timestamp(df.parse(value).getTime())); } } else { throw new UpgradeException("Upgrade code using unsupported class type " + type); } }
From source file:org.executequery.gui.importexport.AbstractImportExportWorker.java
/** * Sets the specified value in the specified position for the * specified java.sql.Type within the prepared statement. * * @param value - the value/*from ww w .j a v a 2 s.co m*/ * @param index - the position within the statement * @param sqlType - the SQL type * @param trim - whether to trim the whitespace from the value * @param df - the DataFormat object for date values */ protected void setValue(String value, int index, int sqlType, boolean trim, DateFormat df) throws Exception { if (value == null) { prepStmnt.setNull(index, sqlType); } else { switch (sqlType) { case Types.TINYINT: byte _byte = Byte.valueOf(value).byteValue(); prepStmnt.setShort(index, _byte); break; case Types.BIGINT: long _long = Long.valueOf(value).longValue(); prepStmnt.setLong(index, _long); break; case Types.SMALLINT: short _short = Short.valueOf(value).shortValue(); prepStmnt.setShort(index, _short); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: if (trim) { value = value.trim(); } prepStmnt.setString(index, value); break; case Types.BIT: case Types.BOOLEAN: String booleanValue = value; if ("t".equalsIgnoreCase(value)) { booleanValue = "true"; } else if ("f".equalsIgnoreCase(value)) { booleanValue = "false"; } boolean _boolean = Boolean.valueOf(booleanValue).booleanValue(); prepStmnt.setBoolean(index, _boolean); break; case Types.NUMERIC: case Types.DECIMAL: prepStmnt.setBigDecimal(index, new BigDecimal(value)); break; case Types.REAL: float _float = Float.valueOf(value).floatValue(); prepStmnt.setFloat(index, _float); break; case Types.FLOAT: case Types.DOUBLE: prepStmnt.setDouble(index, Double.parseDouble(value)); break; case Types.INTEGER: prepStmnt.setInt(index, Integer.parseInt(value)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: // if the date format is null, insert as a char value if (df != null) { java.util.Date j_datetime = df.parse(value); prepStmnt.setDate(index, new java.sql.Date(j_datetime.getTime())); } else { try { prepStmnt.setObject(index, value, sqlType); /* if (sqlType == Types.TIMESTAMP) { prepStmnt.setTimestamp(index, java.sql.Timestamp.valueOf(value)); } else if (sqlType == Types.TIME) { prepStmnt.setTime(index, java.sql.Time.valueOf(value)); } else { prepStmnt.setDate(index, java.sql.Date.valueOf(value)); } */ } // want a more useful message here than what will likely // be returned due to internal driver code on formatting // a SQL date value from string // (ie. could be parsing error, number format etc...) catch (Exception e) { throw new IllegalArgumentException("[ " + MiscUtils.getExceptionName(e) + " ] " + getBundle().getString("AbstractImportExportWorker.dateConversionError")); } } break; case Types.LONGVARBINARY: case Types.BINARY: case Types.BLOB: case Types.CLOB: prepStmnt.setBytes(index, Base64.decode(value)); break; default: prepStmnt.setObject(index, value); break; } } }
From source file:com.squid.core.domain.operators.ExtendedType.java
public static IDomain computeDomain(int data_type, int size, int scale) { switch (data_type) { case Types.BOOLEAN: case Types.BIT:// on PG systems, this is how a boolean is actually represented by the driver return IDomain.BOOLEAN; case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: return IDomain.NUMERIC; /////////////////////////// case Types.REAL: case Types.DOUBLE: case Types.FLOAT: return IDomain.CONTINUOUS; case Types.NUMERIC: case Types.DECIMAL: return scale > 0 || size == 0 ? IDomain.CONTINUOUS : IDomain.NUMERIC; case Types.CHAR: case Types.NCHAR: case Types.VARCHAR: case Types.NVARCHAR: case Types.LONGVARCHAR: case Types.CLOB: return IDomain.STRING; /////////////////////////// case Types.TIME: return IDomain.TIME; case Types.DATE: return IDomain.DATE; case Types.TIMESTAMP: return IDomain.TIMESTAMP; /////////////////////////// default:/*from www. j av a2s.c om*/ return IDomain.UNKNOWN; } }
From source file:funcoes.funcoes.java
@SuppressWarnings("rawtypes") public static Vector<Comparable> proximaLinha(ResultSet rs, ResultSetMetaData rsmd) throws SQLException { Vector<Comparable> LinhaAtual = new Vector<Comparable>(); try {/* w ww.j a v a 2s .co m*/ for (int i = 1; i <= rsmd.getColumnCount(); ++i) { switch (rsmd.getColumnType(i)) { case Types.VARCHAR: LinhaAtual.addElement(rs.getString(i)); break; case Types.TIMESTAMP: LinhaAtual.addElement(rs.getDate(i).toLocaleString().substring(0, 10)); break; case Types.INTEGER: LinhaAtual.addElement(rs.getInt(i)); break; case Types.DECIMAL: LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i))); break; case Types.DOUBLE: LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i))); break; } } } catch (SQLException e) { } return LinhaAtual; }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Get one value into DbValue from ResultSet * //from w w w .j a v a 2 s.c o m * @param rs * @param value * @throws WaarpDatabaseSqlException */ static public void getTrueValue(ResultSet rs, DbValue value) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: value.value = rs.getString(value.column); break; case Types.LONGVARCHAR: value.value = rs.getString(value.column); break; case Types.BIT: value.value = rs.getBoolean(value.column); break; case Types.TINYINT: value.value = rs.getByte(value.column); break; case Types.SMALLINT: value.value = rs.getShort(value.column); break; case Types.INTEGER: value.value = rs.getInt(value.column); break; case Types.BIGINT: value.value = rs.getLong(value.column); break; case Types.REAL: value.value = rs.getFloat(value.column); break; case Types.DOUBLE: value.value = rs.getDouble(value.column); break; case Types.VARBINARY: value.value = rs.getBytes(value.column); break; case Types.DATE: value.value = rs.getDate(value.column); break; case Types.TIMESTAMP: value.value = rs.getTimestamp(value.column); break; case Types.CLOB: value.value = rs.getClob(value.column).getCharacterStream(); break; case Types.BLOB: value.value = rs.getBlob(value.column).getBinaryStream(); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " for " + value.column); } } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Getting values in error: " + value.type + " for " + value.column, e); } }
From source file:jongo.jdbc.JDBCExecutor.java
/** * Utility method which registers in a CallableStatement object the different {@link jongo.jdbc.StoredProcedureParam} * instances in the given list. Returns a List of {@link jongo.jdbc.StoredProcedureParam} with all the OUT parameters * registered in the CallableStatement//from w w w . j a v a 2 s . co m * @param cs the CallableStatement object where the parameters are registered. * @param params a list of {@link jongo.jdbc.StoredProcedureParam} * @return a list of OUT {@link jongo.jdbc.StoredProcedureParam} * @throws SQLException if we fail to register any of the parameters in the CallableStatement */ private static List<StoredProcedureParam> addParameters(final CallableStatement cs, final List<StoredProcedureParam> params) throws SQLException { List<StoredProcedureParam> outParams = new ArrayList<StoredProcedureParam>(); int i = 1; for (StoredProcedureParam p : params) { final Integer sqlType = p.getType(); if (p.isOutParameter()) { l.debug("Adding OUT parameter " + p.toString()); cs.registerOutParameter(i++, sqlType); outParams.add(p); } else { l.debug("Adding IN parameter " + p.toString()); switch (sqlType) { case Types.BIGINT: case Types.INTEGER: case Types.TINYINT: // case Types.NUMERIC: cs.setInt(i++, Integer.valueOf(p.getValue())); break; case Types.DATE: cs.setDate(i++, (Date) JongoUtils.parseValue(p.getValue())); break; case Types.TIME: cs.setTime(i++, (Time) JongoUtils.parseValue(p.getValue())); break; case Types.TIMESTAMP: cs.setTimestamp(i++, (Timestamp) JongoUtils.parseValue(p.getValue())); break; case Types.DECIMAL: cs.setBigDecimal(i++, (BigDecimal) JongoUtils.parseValue(p.getValue())); break; case Types.DOUBLE: cs.setDouble(i++, Double.valueOf(p.getValue())); break; case Types.FLOAT: cs.setLong(i++, Long.valueOf(p.getValue())); break; default: cs.setString(i++, p.getValue()); break; } } } return outParams; }
From source file:org.eclipse.ecr.core.storage.sql.extensions.H2Fulltext.java
protected static String asString(Object data, int type) throws SQLException { if (data == null) { return ""; }//from www . j a va 2s .co m switch (type) { case Types.BIT: case DataType.TYPE_BOOLEAN: case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: case Types.TINYINT: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: return data.toString(); case Types.CLOB: try { if (data instanceof Clob) { data = ((Clob) data).getCharacterStream(); } return IOUtils.readStringAndClose((Reader) data, -1); } catch (IOException e) { throw Message.convert(e); } case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BINARY: case Types.JAVA_OBJECT: case Types.OTHER: case Types.BLOB: case Types.STRUCT: case Types.REF: case Types.NULL: case Types.ARRAY: case DataType.TYPE_DATALINK: case Types.DISTINCT: throw new SQLException("Unsupported column data type: " + type); default: return ""; } }
From source file:org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.java
/** * Convenience method that inserts an individual records into the * JobParameters table./*from w ww.java2 s. co m*/ */ private void insertParameter(Long executionId, ParameterType type, String key, Object value, boolean identifying) { Object[] args = new Object[0]; int[] argTypes = new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.BIGINT, Types.DOUBLE, Types.CHAR }; String identifyingFlag = identifying ? "Y" : "N"; if (type == ParameterType.STRING) { args = new Object[] { executionId, key, type, value, new Timestamp(0L), 0L, 0D, identifyingFlag }; } else if (type == ParameterType.LONG) { args = new Object[] { executionId, key, type, "", new Timestamp(0L), value, new Double(0), identifyingFlag }; } else if (type == ParameterType.DOUBLE) { args = new Object[] { executionId, key, type, "", new Timestamp(0L), 0L, value, identifyingFlag }; } else if (type == ParameterType.DATE) { args = new Object[] { executionId, key, type, "", value, 0L, 0D, identifyingFlag }; } getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); }