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.squid.core.domain.operators.ExtendedType.java
private String getTypeName(int SQLType) { switch (SQLType) { case Types.ARRAY: return "ARRAY"; case Types.BIGINT: return "INTEGER"; case Types.BINARY: return "BINARY"; case Types.BIT: return "BIT"; case Types.BLOB: return "BLOB"; case Types.BOOLEAN: return "BOOLEAN"; case Types.CHAR: return "CHAR"; case Types.CLOB: return "CLOB"; case Types.DATALINK: return "DATALINK"; case Types.DATE: return "DATE"; case Types.DECIMAL: return "DECIMAL"; case Types.DOUBLE: return "DOUBLE"; case Types.FLOAT: return "FLOAT"; case Types.INTEGER: return "INTEGER"; case Types.JAVA_OBJECT: return "JAVA_OBJECT"; case Types.LONGNVARCHAR: return "LONGNVARCHAR"; case Types.LONGVARBINARY: return "LONGVARBINARY"; case Types.NCHAR: return "NCHAR"; case Types.NCLOB: return "NCLOB"; case Types.NULL: return "UNDEFINED";// case Types.NUMERIC: return "NUMERIC"; case Types.NVARCHAR: return "NVARCHAR"; case Types.OTHER: return "UNDEFINED";// case Types.REAL: return "REAL"; case Types.REF: return "REF"; case Types.ROWID: return "ROWID"; case Types.SMALLINT: return "SMALLINT"; case Types.SQLXML: return "SQLXML"; case Types.STRUCT: return "STRUCT"; case Types.TIME: return "TIME"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.TINYINT: return "TINYINT"; case Types.VARBINARY: return "VARBINARY"; case Types.VARCHAR: return "VARCHAR"; default:// w w w .j a v a2s . co m return "UNDEFINED";// } }
From source file:org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplateTests.java
public void testQueryWithRowCallbackHandler() throws SQLException { mockResultSet.next();// w w w .j av a 2 s. c o m ctrlResultSet.setReturnValue(true); mockResultSet.getInt("id"); ctrlResultSet.setReturnValue(1); mockResultSet.getString("forename"); ctrlResultSet.setReturnValue("rod"); mockResultSet.next(); ctrlResultSet.setReturnValue(false); mockResultSet.close(); ctrlResultSet.setVoidCallable(); mockPreparedStatement.setObject(1, new Integer(1), Types.DECIMAL); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setString(2, "UK"); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeQuery(); ctrlPreparedStatement.setReturnValue(mockResultSet); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(SELECT_NAMED_PARAMETERS_PARSED); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(mockDataSource); Map params = new HashMap(); params.put("id", new SqlParameterValue(Types.DECIMAL, new Integer(1))); params.put("country", "UK"); final List customers = new LinkedList(); jt.query(SELECT_NAMED_PARAMETERS, params, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Customer cust = new Customer(); cust.setId(rs.getInt(COLUMN_NAMES[0])); cust.setForename(rs.getString(COLUMN_NAMES[1])); customers.add(cust); } }); assertEquals(1, customers.size()); Customer cust = (Customer) customers.get(0); assertTrue("Customer id was assigned correctly", cust.getId() == 1); assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod")); }
From source file:org.hibernate.dialect.Dialect.java
protected Dialect() { log.info("Using dialect: " + this); sqlFunctions.putAll(STANDARD_AGGREGATE_FUNCTIONS); // standard sql92 functions (can be overridden by subclasses) registerFunction("substring", new SQLFunctionTemplate(Hibernate.STRING, "substring(?1, ?2, ?3)")); registerFunction("locate", new SQLFunctionTemplate(Hibernate.INTEGER, "locate(?1, ?2, ?3)")); registerFunction("trim", new SQLFunctionTemplate(Hibernate.STRING, "trim(?1 ?2 ?3 ?4)")); registerFunction("length", new StandardSQLFunction("length", Hibernate.INTEGER)); registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.INTEGER)); registerFunction("coalesce", new StandardSQLFunction("coalesce")); registerFunction("nullif", new StandardSQLFunction("nullif")); registerFunction("abs", new StandardSQLFunction("abs")); registerFunction("mod", new StandardSQLFunction("mod", Hibernate.INTEGER)); registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE)); registerFunction("upper", new StandardSQLFunction("upper")); registerFunction("lower", new StandardSQLFunction("lower")); registerFunction("cast", new CastFunction()); registerFunction("extract", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)")); //map second/minute/hour/day/month/year to ANSI extract(), override on subclasses registerFunction("second", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)")); registerFunction("minute", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)")); registerFunction("hour", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)")); registerFunction("day", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)")); registerFunction("month", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)")); registerFunction("year", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)")); registerFunction("str", new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)")); // register hibernate types for default use in scalar sqlquery type auto detection registerHibernateType(Types.BIGINT, Hibernate.BIG_INTEGER.getName()); registerHibernateType(Types.BINARY, Hibernate.BINARY.getName()); registerHibernateType(Types.BIT, Hibernate.BOOLEAN.getName()); registerHibernateType(Types.CHAR, Hibernate.CHARACTER.getName()); registerHibernateType(Types.DATE, Hibernate.DATE.getName()); registerHibernateType(Types.DOUBLE, Hibernate.DOUBLE.getName()); registerHibernateType(Types.FLOAT, Hibernate.FLOAT.getName()); registerHibernateType(Types.INTEGER, Hibernate.INTEGER.getName()); registerHibernateType(Types.SMALLINT, Hibernate.SHORT.getName()); registerHibernateType(Types.TINYINT, Hibernate.BYTE.getName()); registerHibernateType(Types.TIME, Hibernate.TIME.getName()); registerHibernateType(Types.TIMESTAMP, Hibernate.TIMESTAMP.getName()); registerHibernateType(Types.VARCHAR, Hibernate.STRING.getName()); registerHibernateType(Types.VARBINARY, Hibernate.BINARY.getName()); registerHibernateType(Types.NUMERIC, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(Types.BLOB, Hibernate.BLOB.getName()); registerHibernateType(Types.CLOB, Hibernate.CLOB.getName()); registerHibernateType(Types.REAL, Hibernate.FLOAT.getName()); }
From source file:com.sr.model.dao.IPamongDAOImpl.java
@Override public boolean insertAkademik(Akademik aca, String nim) { getJdbcTemplate().update(INSERT_AKADEMIK, new Object[] { nim, aca.getSemester(), aca.getBanyak_sks(), aca.getIps() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.DECIMAL, Types.DECIMAL }); return true;//from w ww.j a v a 2 s .co m }
From source file:com.opengamma.masterdb.position.DbPositionMaster.java
/** * Inserts a new document.//from w w w . ja v a 2s . c o m * * @param document the document, not null * @return the new document, not null */ @Override protected PositionDocument insert(final PositionDocument document) { ArgumentChecker.notNull(document.getPosition(), "document.position"); ArgumentChecker.notNull(document.getPosition().getQuantity(), "document.position.quantity"); for (final ManageableTrade trade : document.getPosition().getTrades()) { ArgumentChecker.notNull(trade.getQuantity(), "position.trade.quantity"); ArgumentChecker.notNull(trade.getCounterpartyExternalId(), "position.trade.counterpartyexternalid"); ArgumentChecker.notNull(trade.getTradeDate(), "position.trade.tradedate"); } try (Timer.Context context = _insertTimer.time()) { final long positionId = nextId("pos_master_seq"); final long positionOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : positionId); final UniqueId positionUid = createUniqueId(positionOid, positionId); final ManageablePosition position = document.getPosition(); // the arguments for inserting into the position table final DbMapSqlParameterSource docArgs = new DbMapSqlParameterSource() .addValue("position_id", positionId).addValue("position_oid", positionOid) .addTimestamp("ver_from_instant", document.getVersionFromInstant()) .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant()) .addTimestamp("corr_from_instant", document.getCorrectionFromInstant()) .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant()) .addValue("quantity", position.getQuantity(), Types.DECIMAL) .addValue("provider_scheme", position.getProviderId() != null ? position.getProviderId().getScheme().getName() : null, Types.VARCHAR) .addValue("provider_value", position.getProviderId() != null ? position.getProviderId().getValue() : null, Types.VARCHAR); // the arguments for inserting into the pos_attribute table final List<DbMapSqlParameterSource> posAttrList = Lists.newArrayList(); for (final Entry<String, String> entry : position.getAttributes().entrySet()) { final long posAttrId = nextId("pos_trade_attr_seq"); final DbMapSqlParameterSource posAttrArgs = new DbMapSqlParameterSource() .addValue("attr_id", posAttrId).addValue("pos_id", positionId) .addValue("pos_oid", positionOid).addValue("key", entry.getKey()) .addValue("value", entry.getValue()); posAttrList.add(posAttrArgs); } // the arguments for inserting into the idkey tables final List<DbMapSqlParameterSource> posAssocList = new ArrayList<DbMapSqlParameterSource>(); final Set<Pair<String, String>> schemeValueSet = Sets.newHashSet(); for (final ExternalId id : position.getSecurityLink().getAllExternalIds()) { final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource() .addValue("position_id", positionId).addValue("key_scheme", id.getScheme().getName()) .addValue("key_value", id.getValue()); posAssocList.add(assocArgs); schemeValueSet.add(Pair.of(id.getScheme().getName(), id.getValue())); } // the arguments for inserting into the trade table final List<DbMapSqlParameterSource> tradeList = Lists.newArrayList(); final List<DbMapSqlParameterSource> tradeAssocList = Lists.newArrayList(); final List<DbMapSqlParameterSource> tradeAttributeList = Lists.newArrayList(); for (final ManageableTrade trade : position.getTrades()) { final long tradeId = nextId("pos_master_seq"); final long tradeOid = (trade.getUniqueId() != null ? extractOid(trade.getUniqueId()) : tradeId); final ExternalId counterpartyId = trade.getCounterpartyExternalId(); final DbMapSqlParameterSource tradeArgs = new DbMapSqlParameterSource() .addValue("trade_id", tradeId).addValue("trade_oid", tradeOid) .addValue("position_id", positionId).addValue("position_oid", positionOid) .addValue("quantity", trade.getQuantity()).addDate("trade_date", trade.getTradeDate()) .addTimeAllowNull("trade_time", trade.getTradeTime() != null ? trade.getTradeTime().toLocalTime() : null) .addValue("zone_offset", trade.getTradeTime() != null ? trade.getTradeTime().getOffset().getTotalSeconds() : null, Types.INTEGER) .addValue("cparty_scheme", counterpartyId.getScheme().getName()) .addValue("cparty_value", counterpartyId.getValue()) .addValue("provider_scheme", position.getProviderId() != null ? position.getProviderId().getScheme().getName() : null, Types.VARCHAR) .addValue("provider_value", position.getProviderId() != null ? position.getProviderId().getValue() : null, Types.VARCHAR) .addValue("premium_value", trade.getPremium(), Types.DOUBLE) .addValue("premium_currency", trade.getPremiumCurrency() != null ? trade.getPremiumCurrency().getCode() : null, Types.VARCHAR) .addDateAllowNull("premium_date", trade.getPremiumDate()) .addTimeAllowNull("premium_time", (trade.getPremiumTime() != null ? trade.getPremiumTime().toLocalTime() : null)) .addValue("premium_zone_offset", trade.getPremiumTime() != null ? trade.getPremiumTime().getOffset().getTotalSeconds() : null, Types.INTEGER); tradeList.add(tradeArgs); // trade attributes final Map<String, String> attributes = new HashMap<String, String>(trade.getAttributes()); for (final Entry<String, String> entry : attributes.entrySet()) { final long tradeAttrId = nextId("pos_trade_attr_seq"); final DbMapSqlParameterSource tradeAttributeArgs = new DbMapSqlParameterSource() .addValue("attr_id", tradeAttrId).addValue("trade_id", tradeId) .addValue("trade_oid", tradeOid).addValue("key", entry.getKey()) .addValue("value", entry.getValue()); tradeAttributeList.add(tradeAttributeArgs); } // set the trade uniqueId final UniqueId tradeUid = createUniqueId(tradeOid, tradeId); IdUtils.setInto(trade, tradeUid); trade.setParentPositionId(positionUid); for (final ExternalId id : trade.getSecurityLink().getAllExternalIds()) { final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource() .addValue("trade_id", tradeId).addValue("key_scheme", id.getScheme().getName()) .addValue("key_value", id.getValue()); tradeAssocList.add(assocArgs); schemeValueSet.add(Pair.of(id.getScheme().getName(), id.getValue())); } } final List<DbMapSqlParameterSource> idKeyList = new ArrayList<DbMapSqlParameterSource>(); final String sqlSelectIdKey = getElSqlBundle().getSql("SelectIdKey"); for (final Pair<String, String> pair : schemeValueSet) { final DbMapSqlParameterSource idkeyArgs = new DbMapSqlParameterSource() .addValue("key_scheme", pair.getFirst()).addValue("key_value", pair.getSecond()); if (getJdbcTemplate().queryForList(sqlSelectIdKey, idkeyArgs).isEmpty()) { // select avoids creating unecessary id, but id may still not be used final long idKeyId = nextId("pos_idkey_seq"); idkeyArgs.addValue("idkey_id", idKeyId); idKeyList.add(idkeyArgs); } } final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs); final String sqlIdKey = getElSqlBundle().getSql("InsertIdKey"); final String sqlPosition2IdKey = getElSqlBundle().getSql("InsertPosition2IdKey"); final String sqlTrade = getElSqlBundle().getSql("InsertTrade"); final String sqlTrade2IdKey = getElSqlBundle().getSql("InsertTrade2IdKey"); final String sqlPositionAttributes = getElSqlBundle().getSql("InsertPositionAttributes"); final String sqlTradeAttributes = getElSqlBundle().getSql("InsertTradeAttributes"); getJdbcTemplate().update(sqlDoc, docArgs); getJdbcTemplate().batchUpdate(sqlIdKey, idKeyList.toArray(new DbMapSqlParameterSource[idKeyList.size()])); getJdbcTemplate().batchUpdate(sqlPosition2IdKey, posAssocList.toArray(new DbMapSqlParameterSource[posAssocList.size()])); getJdbcTemplate().batchUpdate(sqlTrade, tradeList.toArray(new DbMapSqlParameterSource[tradeList.size()])); getJdbcTemplate().batchUpdate(sqlTrade2IdKey, tradeAssocList.toArray(new DbMapSqlParameterSource[tradeAssocList.size()])); getJdbcTemplate().batchUpdate(sqlPositionAttributes, posAttrList.toArray(new DbMapSqlParameterSource[posAttrList.size()])); getJdbcTemplate().batchUpdate(sqlTradeAttributes, tradeAttributeList.toArray(new DbMapSqlParameterSource[tradeAttributeList.size()])); // set the uniqueId position.setUniqueId(positionUid); document.setUniqueId(positionUid); return document; } }
From source file:oscar.util.SqlUtils.java
private static Object getNewType(ResultSet rs, int colNum) { int type = 0; try {/*from www .java 2 s . c o m*/ type = rs.getMetaData().getColumnType(colNum); switch (type) { case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: return oscar.Misc.getString(rs, colNum); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return new Integer(rs.getInt(colNum)); case Types.BIGINT: return new Long(rs.getLong(colNum)); case Types.FLOAT: case Types.DECIMAL: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: return new Double(rs.getDouble(colNum)); // case Types.B case Types.BIT: return new Boolean(rs.getBoolean(colNum)); case Types.TIMESTAMP: case Types.DATE: case Types.TIME: return rs.getDate(colNum); default: return rs.getObject(colNum); } } catch (Exception e) { MiscUtils.getLogger().error("Error", e); } return null; }
From source file:org.athenasource.framework.unidbi.Datatypes.java
/** * Returns the corresponding type as defined in {@link java.sql.Types} of the given UniDB datatype. * @param unidbType the UniDB datatype.//from w w w .j a v a 2 s . c o m * @return the corresponding type as defined in {@link java.sql.Types} of the given UniDB datatype. */ public static int getSQLType(int unidbType) { switch (unidbType) { case BOOLEAN: return Types.TINYINT; case TINYINT: return Types.TINYINT; case SMALLINT: return Types.SMALLINT; case INTEGER: return Types.INTEGER; case BIGINT: return Types.BIGINT; case DECIMAL: return Types.DECIMAL; case REAL: return Types.REAL; case DOUBLE: return Types.DOUBLE; case CHAR: return Types.CHAR; case NCHAR: return Types.NCHAR; case VARCHAR: return Types.VARCHAR; case NVARCHAR: return Types.NVARCHAR; case CLOB: // Clob/NClob can be represented as String without any problem. - Oct 16, 2008. // but returns this type should be ok. return Types.CLOB; case NCLOB: return Types.NCLOB; case BLOB: return Types.BLOB; case TIMESTAMP: return Types.TIMESTAMP; default: throw new IllegalArgumentException("[!NO SUCH UNIDB DATA TYPE: " + unidbType + "]"); } }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java
/** * Check whether the given SQL type is numeric. *//*from w w w. j a v a 2 s. co m*/ public static boolean isNumeric(int sqlType) { return (Types.BIT == sqlType) || (Types.BIGINT == sqlType) || (Types.DECIMAL == sqlType) || (Types.DOUBLE == sqlType) || (Types.FLOAT == sqlType) || (Types.INTEGER == sqlType) || (Types.NUMERIC == sqlType) || (Types.REAL == sqlType) || (Types.SMALLINT == sqlType) || (Types.TINYINT == sqlType); }
From source file:org.jumpmind.db.model.Column.java
/** * Tries to parse the default value of the column and returns it as an * object of the corresponding java type. If the value could not be parsed, * then the original definition is returned. * //from w ww .j a v a 2 s .c om * @return The parsed default value */ public Object getParsedDefaultValue() { if ((defaultValue != null) && (defaultValue.length() > 0)) { try { switch (mappedTypeCode) { case Types.TINYINT: case Types.SMALLINT: return new Short(defaultValue); case Types.INTEGER: try { return new Integer(defaultValue); } catch (NumberFormatException e) { return new Long(defaultValue); } case Types.BIGINT: return new Long(defaultValue); case Types.DECIMAL: case Types.NUMERIC: return new BigDecimal(defaultValue); case Types.REAL: return new Float(defaultValue); case Types.DOUBLE: case Types.FLOAT: return new Double(defaultValue); case Types.DATE: return Date.valueOf(defaultValue); case Types.TIME: return Time.valueOf(defaultValue); case Types.TIMESTAMP: return Timestamp.valueOf(defaultValue); case Types.BIT: return FormatUtils.toBoolean(defaultValue); default: if (PlatformUtils.supportsJava14JdbcTypes() && (mappedTypeCode == PlatformUtils.determineBooleanTypeCode())) { return FormatUtils.toBoolean(defaultValue); } break; } } catch (NumberFormatException ex) { return null; } catch (IllegalArgumentException ex) { return null; } } return defaultValue; }
From source file:com.squid.core.domain.operators.ExtendedType.java
public static int FromTypeName(String SQLName) { if (SQLName.equals("ARRAY")) { return Types.ARRAY; }/*from w w w .j av a 2 s . c o m*/ if (SQLName.equals("INTEGER")) { return Types.INTEGER; } if (SQLName.equals("BINARY")) { return Types.BINARY; } if (SQLName.equals("BIT")) { return Types.BIT; } if (SQLName.equals("BLOB")) { return Types.BLOB; } if (SQLName.equals("BOOLEAN")) { return Types.BOOLEAN; } if (SQLName.equals("CHAR")) { return Types.CHAR; } if (SQLName.equals("CLOB")) { return Types.CLOB; } if (SQLName.equals("DATALINK")) { return Types.DATALINK; } if (SQLName.equals("DATE")) { return Types.DATE; } if (SQLName.equals("DECIMAL")) { return Types.DECIMAL; } if (SQLName.equals("DOUBLE")) { return Types.DOUBLE; } if (SQLName.equals("FLOAT")) { return Types.FLOAT; } if (SQLName.equals("JAVA_OBJECT")) { return Types.JAVA_OBJECT; } if (SQLName.equals("LONGNVARCHAR")) { return Types.LONGNVARCHAR; } if (SQLName.equals("LONGVARBINARY")) { return Types.LONGVARBINARY; } if (SQLName.equals("NCHAR")) { return Types.NCHAR; } if (SQLName.equals("NCLOB")) { return Types.NCLOB; } if (SQLName.equals("UNDEFINED")) { return Types.OTHER; } if (SQLName.equals("NUMERIC")) { return Types.NUMERIC; } if (SQLName.equals("NVARCHAR")) { return Types.NVARCHAR; } if (SQLName.equals("REAL")) { return Types.REAL; } if (SQLName.equals("REF")) { return Types.REF; } if (SQLName.equals("ROWID")) { return Types.ROWID; } if (SQLName.equals("SMALLINT")) { return Types.SMALLINT; } if (SQLName.equals("SQLXML")) { return Types.SQLXML; } if (SQLName.equals("STRUCT")) { return Types.STRUCT; } if (SQLName.equals("TIME")) { return Types.TIME; } if (SQLName.equals("TIMESTAMP")) { return Types.TIMESTAMP; } if (SQLName.equals("TINYINT")) { return Types.TINYINT; } if (SQLName.equals("VARCHAR")) { return Types.VARCHAR; } if (SQLName.equals("VARBINARY")) { return Types.VARBINARY; } return Types.OTHER; }