List of usage examples for java.sql Types NUMERIC
int NUMERIC
To view the source code for java.sql Types NUMERIC.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC
.
From source file:org.hxzon.util.db.springjdbc.StatementCreatorUtils.java
/** * Derive a default SQL type from the given Java type. * @param javaType the Java type to translate * @return the corresponding SQL type, or {@code null} if none found */// w ww .ja v a 2 s . c o m public static int javaTypeToSqlParameterType(Class<?> javaType) { Integer sqlType = javaTypeToSqlTypeMap.get(javaType); if (sqlType != null) { return sqlType; } if (Number.class.isAssignableFrom(javaType)) { return Types.NUMERIC; } if (isStringValue(javaType)) { return Types.VARCHAR; } if (isDateValue(javaType) || Calendar.class.isAssignableFrom(javaType)) { return Types.TIMESTAMP; } return SqlTypeValue.TYPE_UNKNOWN; }
From source file:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java
/** * {@inheritDoc}//from w w w. ja v a 2s . c om */ protected String getValueAsString(Column column, Object value) { if (value == null) { return "NULL"; } StringBuffer result = new StringBuffer(); switch (column.getTypeCode()) { case Types.REAL: case Types.NUMERIC: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: // SQL Server does not want quotes around the value if (!(value instanceof String) && (getValueNumberFormat() != null)) { result.append(getValueNumberFormat().format(value)); } else { result.append(value.toString()); } break; case Types.DATE: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value instanceof String ? (String) value : getValueDateFormat().format(value)); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; case Types.TIME: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value instanceof String ? (String) value : getValueTimeFormat().format(value)); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; case Types.TIMESTAMP: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value.toString()); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; } return super.getValueAsString(column, value); }
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;/*from ww w .ja v a2 s . c om*/ 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.springframework.jdbc.object.SqlUpdateTests.java
public void testUpdateIntInt() throws SQLException { mockPreparedStatement.setObject(1, new Integer(1), Types.NUMERIC); mockPreparedStatement.setObject(2, new Integer(1), Types.NUMERIC); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeUpdate(); ctrlPreparedStatement.setReturnValue(1); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); }//from w ww.ja v a 2 s . c o m mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(UPDATE_INT_INT); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); IntIntUpdater pc = new IntIntUpdater(); int rowsAffected = pc.run(1, 1); assertEquals(1, rowsAffected); }
From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java
public void updateLogoImage(LogoImage logoImage, InputStream is) { if (logoImage.isPrimary()) { getExtendedJdbcTemplate().update( getBoundSql("ARCHITECTURE_WEB.RESET_LOGO_IMAGE_BY_OBJECT_TYPE_AND_OBJECT_ID").getSql(), new SqlParameterValue(Types.INTEGER, logoImage.getObjectType()), new SqlParameterValue(Types.NUMERIC, logoImage.getObjectId())); }/* ww w. j a va 2 s . c om*/ getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.UPDATE_LOGO_IMAGE").getSql(), new SqlParameterValue(Types.NUMERIC, logoImage.getObjectType()), new SqlParameterValue(Types.NUMERIC, logoImage.getObjectId()), new SqlParameterValue(Types.NUMERIC, logoImage.isPrimary() ? 1 : 0), new SqlParameterValue(Types.VARCHAR, logoImage.getFilename()), new SqlParameterValue(Types.NUMERIC, logoImage.getImageSize()), new SqlParameterValue(Types.VARCHAR, logoImage.getImageContentType()), new SqlParameterValue(Types.DATE, logoImage.getModifiedDate()), new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId())); if (is != null) updateImageImputStream(logoImage, is); }
From source file:architecture.ee.web.community.profile.dao.jdbc.JdbcProfileDao.java
public ProfileImage getProfileImageById(Long profileImageId) throws ProfileImageNotFoundException { try {// ww w . j ava2s . c om return getExtendedJdbcTemplate().queryForObject( getBoundSql("ARCHITECTURE_COMMUNITY.SELECT_PROFILE_IMAGE_BY_ID").getSql(), imageMapper, new SqlParameterValue(Types.NUMERIC, profileImageId)); } catch (DataAccessException e) { e.printStackTrace(); throw new ProfileImageNotFoundException(e); } }
From source file:org.castor.cpa.persistence.sql.keygen.HighLowKeyGenerator.java
/** * Initialize the HIGH-LOW key generator. * //from ww w . j av a 2 s.com * @param factory A PersistenceFactory instance. * @param params Database engine specific parameters. * @param sqlType A SQLTypidentifier. * @throws MappingException if this key generator is not compatible with the * persistance factory. */ public HighLowKeyGenerator(final PersistenceFactory factory, final Properties params, final int sqlType) throws MappingException { super(factory); _factory = factory; _sqlType = sqlType; 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); } initFromParameters(params); }
From source file:org.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes atts, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); Connection conn = DataSourceUtils.getConnection(dataSource); ResultSet rs = null;/*from ww w . jav a2 s. co m*/ Statement stmt = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM " + tableName); for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { colTypes.put(rs.getMetaData().getColumnName(i + 1).toUpperCase(), rs.getMetaData().getColumnType(i + 1)); } } catch (SQLException e) { LOG.error("While", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { LOG.error("While closing statement", e); } } if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("While closing result set", e); } } DataSourceUtils.releaseConnection(conn, dataSource); } for (int i = 0; i < atts.getLength(); i++) { Integer colType = colTypes.get(atts.getQName(i).toUpperCase()); if (colType == null) { LOG.warn("No column type found for {}", atts.getQName(i).toUpperCase()); colType = Types.VARCHAR; } switch (colType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.TINYINT: try { query.setParameter(i + 1, Integer.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(atts.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(atts.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; default: query.setParameter(i + 1, atts.getValue(i)); } } }
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:/*w ww. j a va2 s .com*/ return java.sql.Timestamp.class; default: return Object.class; } }