List of usage examples for java.sql Types SMALLINT
int SMALLINT
To view the source code for java.sql Types SMALLINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type 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;/* ww w.ja v a 2 s. co m*/ 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.symmetric.service.impl.FileSyncService.java
public void saveFileTriggerRouter(FileTriggerRouter fileTriggerRouter) { fileTriggerRouter.setLastUpdateTime(new Date()); if (0 == sqlTemplate.update(getSql("updateFileTriggerRouterSql"), new Object[] { fileTriggerRouter.isEnabled() ? 1 : 0, fileTriggerRouter.isInitialLoadEnabled() ? 1 : 0, fileTriggerRouter.getTargetBaseDir(), fileTriggerRouter.getConflictStrategy().name(), fileTriggerRouter.getLastUpdateBy(), fileTriggerRouter.getLastUpdateTime(), fileTriggerRouter.getFileTrigger().getTriggerId(), fileTriggerRouter.getRouter().getRouterId() }, new int[] { Types.SMALLINT, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR })) { fileTriggerRouter.setCreateTime(fileTriggerRouter.getLastUpdateTime()); sqlTemplate.update(getSql("insertFileTriggerRouterSql"), new Object[] { fileTriggerRouter.isEnabled() ? 1 : 0, fileTriggerRouter.isInitialLoadEnabled() ? 1 : 0, fileTriggerRouter.getTargetBaseDir(), fileTriggerRouter.getConflictStrategy().name(), fileTriggerRouter.getCreateTime(), fileTriggerRouter.getLastUpdateBy(), fileTriggerRouter.getLastUpdateTime(), fileTriggerRouter.getFileTrigger().getTriggerId(), fileTriggerRouter.getRouter().getRouterId() }, new int[] { Types.SMALLINT, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR }); }/*w ww.ja va2s . c o m*/ }
From source file:org.netflux.core.FieldMetadata.java
/** * Returns a string representation of the provided type. * /*from w ww . ja va 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:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectOracle.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;/*from w w w .j a va 2 s . c o m*/ case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); 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; case Types.OTHER: ColumnType type = column.getType(); if (type.isId()) { setId(ps, index, value); return; } else if (type == ColumnType.FTSTORED) { ps.setString(index, (String) value); return; } throw new SQLException("Unhandled type: " + column.getType()); default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
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 w w w . j ava2 s . c o 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.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:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.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 ww .java 2 s .com*/ case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; 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: ps.setTimestamp(index, getTimestampFromCalendar((Calendar) value)); return; case Types.ARRAY: int jdbcBaseType = column.getJdbcBaseType(); String jdbcBaseTypeName = column.getSqlBaseTypeString(); if (jdbcBaseType == Types.TIMESTAMP) { value = getTimestampFromCalendar((Serializable[]) value); } Array array = ps.getConnection().createArrayOf(jdbcBaseTypeName, (Object[]) value); ps.setArray(index, array); return; case Types.OTHER: ColumnType type = column.getType(); if (type.isId()) { setId(ps, index, value); return; } else if (type == ColumnType.FTSTORED) { ps.setString(index, (String) value); return; } throw new SQLException("Unhandled type: " + column.getType()); default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
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 .jav 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:com.tesora.dve.db.NativeType.java
public boolean isIntegralType() { return dataType == Types.BIGINT || dataType == Types.INTEGER || dataType == Types.TINYINT || dataType == Types.SMALLINT; }
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);//from www . j a v a2 s . 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; }