List of usage examples for java.sql Types FLOAT
int FLOAT
To view the source code for java.sql Types FLOAT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type FLOAT
.
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java
/** * Check whether the given SQL type is numeric. *//*ww w . ja va2 s. c o 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.apache.synapse.mediators.db.AbstractDBMediator.java
/** * Return a Prepared statement for the given Statement object, which is ready to be executed * * @param stmnt SQL stataement to be executed * @param con The connection to be used * @param msgCtx Current message context * @return a PreparedStatement/*from www .ja v a 2 s . c o m*/ * @throws SQLException on error */ protected PreparedStatement getPreparedStatement(Statement stmnt, Connection con, MessageContext msgCtx) throws SQLException { SynapseLog synLog = getLog(msgCtx); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Getting a connection from DataSource " + getDSName() + " and preparing statement : " + stmnt.getRawStatement()); } if (con == null) { String msg = "Connection from DataSource " + getDSName() + " is null."; log.error(msg); throw new SynapseException(msg); } if (dataSource instanceof BasicDataSource) { BasicDataSource basicDataSource = (BasicDataSource) dataSource; int numActive = basicDataSource.getNumActive(); int numIdle = basicDataSource.getNumIdle(); String connectionId = Integer.toHexString(con.hashCode()); DBPoolView dbPoolView = getDbPoolView(); if (dbPoolView != null) { dbPoolView.setNumActive(numActive); dbPoolView.setNumIdle(numIdle); dbPoolView.updateConnectionUsage(connectionId); } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("[ DB Connection : " + con + " ]"); synLog.traceOrDebug("[ DB Connection instance identifier : " + connectionId + " ]"); synLog.traceOrDebug("[ Number of Active Connection : " + numActive + " ]"); synLog.traceOrDebug("[ Number of Idle Connection : " + numIdle + " ]"); } } PreparedStatement ps = con.prepareStatement(stmnt.getRawStatement()); // set parameters if any List<Statement.Parameter> params = stmnt.getParameters(); int column = 1; for (Statement.Parameter param : params) { if (param == null) { continue; } String value = (param.getPropertyName() != null ? param.getPropertyName() : param.getXpath().stringValueOf(msgCtx)); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting as parameter : " + column + " value : " + value + " as JDBC Type : " + param.getType() + "(see java.sql.Types for valid " + "types)"); } switch (param.getType()) { // according to J2SE 1.5 /docs/guide/jdbc/getstart/mapping.html case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { if (value != null && value.length() != 0) { ps.setString(column++, value); } else { ps.setString(column++, null); } break; } case Types.NUMERIC: case Types.DECIMAL: { if (value != null && value.length() != 0) { ps.setBigDecimal(column++, new BigDecimal(value)); } else { ps.setBigDecimal(column++, null); } break; } case Types.BIT: { if (value != null && value.length() != 0) { ps.setBoolean(column++, Boolean.parseBoolean(value)); } else { ps.setNull(column++, Types.BIT); } break; } case Types.TINYINT: { if (value != null && value.length() != 0) { ps.setByte(column++, Byte.parseByte(value)); } else { ps.setNull(column++, Types.TINYINT); } break; } case Types.SMALLINT: { if (value != null && value.length() != 0) { ps.setShort(column++, Short.parseShort(value)); } else { ps.setNull(column++, Types.SMALLINT); } break; } case Types.INTEGER: { if (value != null && value.length() != 0) { ps.setInt(column++, Integer.parseInt(value)); } else { ps.setNull(column++, Types.INTEGER); } break; } case Types.BIGINT: { if (value != null && value.length() != 0) { ps.setLong(column++, Long.parseLong(value)); } else { ps.setNull(column++, Types.BIGINT); } break; } case Types.REAL: { if (value != null && value.length() != 0) { ps.setFloat(column++, Float.parseFloat(value)); } else { ps.setNull(column++, Types.REAL); } break; } case Types.FLOAT: { if (value != null && value.length() != 0) { ps.setDouble(column++, Double.parseDouble(value)); } else { ps.setNull(column++, Types.FLOAT); } break; } case Types.DOUBLE: { if (value != null && value.length() != 0) { ps.setDouble(column++, Double.parseDouble(value)); } else { ps.setNull(column++, Types.DOUBLE); } break; } // skip BINARY, VARBINARY and LONGVARBINARY case Types.DATE: { if (value != null && value.length() != 0) { ps.setDate(column++, Date.valueOf(value)); } else { ps.setNull(column++, Types.DATE); } break; } case Types.TIME: { if (value != null && value.length() != 0) { ps.setTime(column++, Time.valueOf(value)); } else { ps.setNull(column++, Types.TIME); } break; } case Types.TIMESTAMP: { if (value != null && value.length() != 0) { ps.setTimestamp(column++, Timestamp.valueOf(value)); } else { ps.setNull(column++, Types.TIMESTAMP); } break; } // skip CLOB, BLOB, ARRAY, DISTINCT, STRUCT, REF, JAVA_OBJECT default: { String msg = "Trying to set an un-supported JDBC Type : " + param.getType() + " against column : " + column + " and statement : " + stmnt.getRawStatement() + " used by a DB mediator against DataSource : " + getDSName() + " (see java.sql.Types for valid type values)"; handleException(msg, msgCtx); } } } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Successfully prepared statement : " + stmnt.getRawStatement() + " against DataSource : " + getDSName()); } return ps; }
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; }
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. * // w w w . j a v a 2 s. co m * @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:org.latticesoft.util.resource.dao.Param.java
private void setValueToStatement(Object o, PreparedStatement pstmt) throws SQLException { if (log.isDebugEnabled()) { log.debug(this.sqlIndex + "=" + o); }/*from w ww . ja v a 2s . com*/ switch (this.sqlType) { case Types.VARCHAR: case Types.CHAR: String s = (String) o; pstmt.setString(this.sqlIndex, s); break; case Types.BOOLEAN: if (o != null && o instanceof Boolean) { boolean b = ((Boolean) o).booleanValue(); pstmt.setBoolean(this.sqlIndex, b); } break; case Types.INTEGER: if (o != null && o instanceof Integer) { int i = ((Integer) o).intValue(); pstmt.setInt(this.sqlIndex, i); } break; case Types.SMALLINT: if (o != null && o instanceof Short) { short ss = ((Short) o).shortValue(); pstmt.setShort(this.sqlIndex, ss); } break; case Types.TINYINT: if (o != null && o instanceof Byte) { byte bb = ((Byte) o).byteValue(); pstmt.setByte(this.sqlIndex, bb); } break; case Types.BIGINT: if (o != null && o instanceof Long) { long l = ((Long) o).longValue(); pstmt.setLong(this.sqlIndex, l); } break; case Types.DOUBLE: if (o != null && o instanceof Double) { double dd = ((Double) o).doubleValue(); pstmt.setDouble(this.sqlIndex, dd); } break; case Types.FLOAT: if (o != null && o instanceof Float) { float f = ((Float) o).floatValue(); pstmt.setFloat(this.sqlIndex, f); } break; case Types.NUMERIC: if (o != null && o instanceof BigDecimal) { BigDecimal bd = (BigDecimal) o; pstmt.setBigDecimal(this.sqlIndex, bd); } break; case Types.TIMESTAMP: if (o != null && o instanceof Timestamp) { Timestamp ts = (Timestamp) o; pstmt.setTimestamp(this.sqlIndex, ts); } break; case Types.NULL: if (log.isDebugEnabled()) { log.debug(this.sqlIndex + " IS NULL"); } pstmt.setNull(this.sqlIndex, Types.NULL); break; default: if (o != null) { pstmt.setObject(this.sqlIndex, o); } } }
From source file:org.netflux.core.FieldMetadata.java
/** * Returns a string representation of the provided type. * /*from w w w. jav a 2 s . c o m*/ * @param type the type from {@link Types} to transform to a string. * @return a string representation of the provided type. */ public static String typeToString(int type) { switch (type) { case Types.ARRAY: return "ARRAY"; case Types.BIGINT: return "BIGINT"; 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.DISTINCT: return "DISTINCT"; case Types.DOUBLE: return "DOUBLE"; case Types.FLOAT: return "FLOAT"; case Types.INTEGER: return "INTEGER"; case Types.JAVA_OBJECT: return "JAVA_OBJECT"; case Types.LONGVARBINARY: return "LONGVARBINARY"; case Types.LONGVARCHAR: return "LONGVARCHAR"; case Types.NULL: return "NULL"; case Types.NUMERIC: return "NUMERIC"; case Types.OTHER: return "OTHER"; case Types.REAL: return "REAL"; case Types.REF: return "REF"; case Types.SMALLINT: return "SMALLINT"; 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: return "*unsupported type*"; } }
From source file:com.tesora.dve.db.NativeType.java
public boolean isFloatType() { return dataType == Types.FLOAT || dataType == Types.REAL || dataType == Types.DOUBLE; }
From source file:com.tesora.dve.db.NativeType.java
public boolean isNumericType() { return dataType == Types.BIGINT || dataType == Types.DECIMAL || dataType == Types.DOUBLE || dataType == Types.FLOAT || dataType == Types.INTEGER || dataType == Types.NUMERIC || dataType == Types.REAL || dataType == Types.TINYINT || dataType == Types.SMALLINT; }
From source file:jeeves.resources.dbms.Dbms.java
private Element buildElement(ResultSet rs, int col, String name, int type, Hashtable<String, String> formats) throws SQLException { String value = null;// w w w . j a v a2 s. com switch (type) { case Types.DATE: Date date = rs.getDate(col + 1); if (date == null) value = null; else { String format = formats.get(name); SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_DATE_FORMAT) : new SimpleDateFormat(format); value = df.format(date); } break; case Types.TIME: Time time = rs.getTime(col + 1); if (time == null) value = null; else { String format = formats.get(name); SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIME_FORMAT) : new SimpleDateFormat(format); value = df.format(time); } break; case Types.TIMESTAMP: Timestamp timestamp = rs.getTimestamp(col + 1); if (timestamp == null) value = null; else { String format = formats.get(name); SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIMESTAMP_FORMAT) : new SimpleDateFormat(format); value = df.format(timestamp); } break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: long l = rs.getLong(col + 1); if (rs.wasNull()) value = null; else { String format = formats.get(name); if (format == null) value = l + ""; else { DecimalFormat df = new DecimalFormat(format); value = df.format(l); } } break; case Types.DECIMAL: case Types.FLOAT: case Types.DOUBLE: case Types.REAL: case Types.NUMERIC: double n = rs.getDouble(col + 1); if (rs.wasNull()) value = null; else { String format = formats.get(name); if (format == null) { value = n + ""; // --- this fix is mandatory for oracle // --- that shit returns integers like xxx.0 if (value.endsWith(".0")) value = value.substring(0, value.length() - 2); } else { DecimalFormat df = new DecimalFormat(format); value = df.format(n); } } break; default: value = rs.getString(col + 1); if (value != null) { value = stripIllegalChars(value); } break; } return new Element(name).setText(value); }
From source file:org.jumpmind.vaadin.ui.common.CommonUiUtils.java
@SuppressWarnings("unchecked") public static Grid putResultsInGrid(final ResultSet rs, List<Integer> pkcolumns, int maxResultSize, final boolean showRowNumbers, String... excludeValues) throws SQLException { final Grid grid = new Grid(); grid.setImmediate(true);//w w w . jav a 2s . c o m grid.setSelectionMode(SelectionMode.MULTI); grid.setColumnReorderingAllowed(true); grid.setData(new HashMap<Object, List<Object>>()); final ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); grid.addColumn("#", Integer.class).setHeaderCaption("#").setHidable(true); Set<String> columnNames = new HashSet<String>(); Set<Integer> skipColumnIndexes = new HashSet<Integer>(); int[] types = new int[columnCount]; for (int i = 1; i <= columnCount; i++) { String realColumnName = meta.getColumnName(i); String columnName = realColumnName; if (!Arrays.asList(excludeValues).contains(columnName)) { int index = 1; while (columnNames.contains(columnName)) { columnName = realColumnName + "_" + index++; } columnNames.add(columnName); Class<?> typeClass = Object.class; int type = meta.getColumnType(i); types[i - 1] = type; switch (type) { case Types.FLOAT: case Types.DOUBLE: case Types.NUMERIC: case Types.REAL: case Types.DECIMAL: typeClass = BigDecimal.class; break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.INTEGER: typeClass = Long.class; break; case Types.VARCHAR: case Types.CHAR: case Types.NVARCHAR: case Types.NCHAR: case Types.CLOB: typeClass = String.class; default: break; } Column column = grid.addColumn(columnName, typeClass).setHeaderCaption(columnName).setHidable(true); if (typeClass.equals(Long.class)) { column.setConverter(new StringToLongConverter() { private static final long serialVersionUID = 1L; @Override public String convertToPresentation(Long value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return NULL_TEXT; } else { return value.toString(); } } }); } else if (typeClass.equals(BigDecimal.class)) { column.setConverter(new StringToBigDecimalConverter() { private static final long serialVersionUID = 1L; @Override public String convertToPresentation(BigDecimal value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return NULL_TEXT; } else { return value.toString(); } } }); } else { column.setConverter(new Converter<String, Object>() { private static final long serialVersionUID = 1L; @Override public Object convertToModel(String value, Class<? extends Object> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return null; } @Override public String convertToPresentation(Object value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return NULL_TEXT; } else { return value.toString(); } } @Override public Class<Object> getModelType() { return Object.class; } @Override public Class<String> getPresentationType() { return String.class; } }); } } else { skipColumnIndexes.add(i - 1); } } int rowNumber = 1; while (rs.next() && rowNumber <= maxResultSize) { Object[] row = new Object[columnNames.size() + 1]; row[0] = new Integer(rowNumber); int rowIndex = 1; for (int i = 0; i < columnCount; i++) { if (!skipColumnIndexes.contains(i)) { Object o = getObject(rs, i + 1); int type = types[i]; switch (type) { case Types.FLOAT: case Types.DOUBLE: case Types.REAL: case Types.NUMERIC: case Types.DECIMAL: if (o != null && !(o instanceof BigDecimal)) { o = new BigDecimal(castToNumber(o.toString())); } break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.INTEGER: if (o != null && !(o instanceof Long)) { o = new Long(castToNumber(o.toString())); } break; default: break; } List<Object> primaryKeys = new ArrayList<Object>(); for (Integer pkcolumn : pkcolumns) { primaryKeys.add(getObject(rs, pkcolumn + 1)); } ((HashMap<Object, List<Object>>) grid.getData()).put(o, primaryKeys); row[rowIndex] = o; rowIndex++; } } grid.addRow(row); rowNumber++; } if (rowNumber < 100) { grid.getColumn("#").setWidth(75); } else if (rowNumber < 1000) { grid.getColumn("#").setWidth(95); } else { grid.getColumn("#").setWidth(115); } if (!showRowNumbers) { grid.getColumn("#").setHidden(true); } else { grid.setFrozenColumnCount(1); } return grid; }