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:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { int jdbcType = rs.getMetaData().getColumnType(index); if (column.getJdbcType() == Types.ARRAY && jdbcType != Types.ARRAY) { jdbcType = column.getJdbcBaseType(); } else {/*w w w . j av a 2s . c om*/ jdbcType = column.getJdbcType(); } switch (jdbcType) { case Types.VARCHAR: case Types.CLOB: return getFromResultSetString(rs, index, column); case Types.BIT: return rs.getBoolean(index); case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getCalendarFromTimestamp(rs.getTimestamp(index)); case Types.ARRAY: Array array = rs.getArray(index); if (array == null) { return null; } if (array.getBaseType() == Types.TIMESTAMP) { return getCalendarFromTimestamp((Timestamp[]) array.getArray()); } else { return (Serializable) array.getArray(); } case Types.OTHER: ColumnType type = column.getType(); if (type.isId()) { return getId(rs, index); } throw new SQLException("Unhandled type: " + column.getType()); } throw new SQLException( "Unhandled JDBC type: " + column.getJdbcType() + " for type " + column.getType().toString()); }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
protected Object getObjectValue(String value, Column column, BinaryEncoding encoding, boolean useVariableDates, boolean fitToColumn) throws DecoderException { Object objectValue = value;//w w w. j a v a2s .com int type = column.getMappedTypeCode(); if ((value == null || (getDdlBuilder().getDatabaseInfo().isEmptyStringNulled() && value.equals(""))) && column.isRequired() && column.isOfTextType()) { objectValue = REQUIRED_FIELD_NULL_SUBSTITUTE; } if (value != null) { if (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME) { objectValue = parseDate(type, value, useVariableDates); } else if (type == Types.CHAR) { String charValue = value.toString(); if ((StringUtils.isBlank(charValue) && getDdlBuilder().getDatabaseInfo().isBlankCharColumnSpacePadded()) || (StringUtils.isNotBlank(charValue) && getDdlBuilder().getDatabaseInfo().isNonBlankCharColumnSpacePadded())) { objectValue = StringUtils.rightPad(value.toString(), column.getSizeAsInt(), ' '); } } else if (type == Types.BIGINT) { objectValue = parseBigInteger(value); } else if (type == Types.INTEGER || type == Types.SMALLINT || type == Types.BIT || type == Types.TINYINT) { objectValue = parseInteger(value); } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.FLOAT || type == Types.DOUBLE || type == Types.REAL) { objectValue = parseBigDecimal(value); } else if (type == Types.BOOLEAN) { objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE; } else if (!(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY)) && !(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY)) && (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY || // SQLServer ntext type type == -10)) { if (encoding == BinaryEncoding.NONE) { objectValue = value.getBytes(); } else if (encoding == BinaryEncoding.BASE64) { objectValue = Base64.decodeBase64(value.getBytes()); } else if (encoding == BinaryEncoding.HEX) { objectValue = Hex.decodeHex(value.toCharArray()); } } else if (type == Types.ARRAY) { objectValue = createArray(column, value); } } if (objectValue instanceof String) { String stringValue = cleanTextForTextBasedColumns((String) objectValue); int size = column.getSizeAsInt(); if (fitToColumn && size > 0 && stringValue.length() > size) { stringValue = stringValue.substring(0, size); } objectValue = stringValue; } return objectValue; }
From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.java
private void setArgument(PreparedStatement pstmt, String argument, int targetSqlType, int index) throws SQLException { switch (targetSqlType) { case Types.INTEGER: pstmt.setInt(index, Integer.parseInt(argument)); break;/*from w ww. j a v a2 s . co m*/ case Types.DECIMAL: case Types.NUMERIC: pstmt.setBigDecimal(index, new BigDecimal(argument)); break; case Types.DOUBLE: case Types.FLOAT: pstmt.setDouble(index, Double.parseDouble(argument)); break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: pstmt.setString(index, argument); break; case Types.BIT: case Types.BOOLEAN: pstmt.setBoolean(index, Boolean.parseBoolean(argument)); break; case Types.BIGINT: pstmt.setLong(index, Long.parseLong(argument)); break; case Types.DATE: pstmt.setDate(index, Date.valueOf(argument)); break; case Types.REAL: pstmt.setFloat(index, Float.parseFloat(argument)); break; case Types.TINYINT: pstmt.setByte(index, Byte.parseByte(argument)); break; case Types.SMALLINT: pstmt.setShort(index, Short.parseShort(argument)); break; case Types.TIMESTAMP: pstmt.setTimestamp(index, Timestamp.valueOf(argument)); break; case Types.TIME: pstmt.setTime(index, Time.valueOf(argument)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: pstmt.setBytes(index, argument.getBytes()); break; case Types.NULL: pstmt.setNull(index, targetSqlType); break; default: pstmt.setObject(index, argument, targetSqlType); } }
From source file:org.eclipse.ecr.core.storage.sql.extensions.H2Fulltext.java
private static Object asObject(String string, int type) throws SQLException { switch (type) { case Types.BIGINT: return Long.valueOf(string); case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: return Integer.valueOf(string); case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: return string; default:/* w w w. j a v a2 s . c o m*/ throw new SQLException("Unsupport data type for primary key: " + type); } }
From source file:org.jumpmind.symmetric.io.data.DbFill.java
private Object generateRandomValueForColumn(Column column) { Object objectValue = null;/* w w w. ja v a2 s. c om*/ int type = column.getMappedTypeCode(); if (column.isEnum()) { objectValue = column.getEnumValues()[new Random().nextInt(column.getEnumValues().length)]; } else if (column.isTimestampWithTimezone()) { objectValue = String.format("%s %s", FormatUtils.TIMESTAMP_FORMATTER.format(randomDate()), AppUtils.getTimezoneOffset()); } else if (type == Types.DATE) { objectValue = DateUtils.truncate(randomDate(), Calendar.DATE); } else if (type == Types.TIMESTAMP || type == Types.TIME) { objectValue = randomTimestamp(); } else if (type == Types.INTEGER || type == Types.BIGINT) { objectValue = randomInt(); } else if (type == Types.SMALLINT) { objectValue = randomSmallInt(column.getJdbcTypeName().toLowerCase().contains("unsigned")); } else if (type == Types.FLOAT) { objectValue = randomFloat(); } else if (type == Types.DOUBLE) { objectValue = randomDouble(); } else if (type == Types.TINYINT) { objectValue = randomTinyInt(); } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.REAL) { objectValue = randomBigDecimal(column.getSizeAsInt(), column.getScale()); } else if (type == Types.BOOLEAN || type == Types.BIT) { objectValue = randomBoolean(); } else if (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY || // SQLServer text type type == -10) { objectValue = randomBytes(); } else if (type == Types.ARRAY) { objectValue = null; } else if (type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.CHAR || type == Types.CLOB) { int size = 0; // Assume if the size is 0 there is no max size configured. if (column.getSizeAsInt() != 0) { size = column.getSizeAsInt() > 50 ? 50 : column.getSizeAsInt(); } else { // No max length so default to 50 size = 50; } objectValue = randomString(size); } else if (type == Types.OTHER) { if ("UUID".equalsIgnoreCase(column.getJdbcTypeName())) { objectValue = randomUUID(); } } return objectValue; }
From source file:dao.MetricsDAO.java
public static String updateMetricValues(int id, Map<String, String[]> params) { String message = "Internal error"; if (params == null || params.size() == 0) { return "Empty post body"; }/*from w w w . j a va2 s . com*/ boolean needAnd = false; String setClause = ""; String description = ""; String[] descArray = null; List<Object> args = new ArrayList<Object>(); List<Integer> argTypes = new ArrayList<Integer>(); if (params.containsKey(MetricRowMapper.METRIC_DESCRIPTION_COLUMN)) { descArray = params.get(MetricRowMapper.METRIC_DESCRIPTION_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DESCRIPTION)) { descArray = params.get(MetricRowMapper.METRIC_MODULE_DESCRIPTION); } if (descArray != null && descArray.length > 0) { description = descArray[0]; setClause += MetricRowMapper.METRIC_DESCRIPTION_COLUMN + " = ? "; needAnd = true; args.add(description); argTypes.add(Types.VARCHAR); } String dashboard = ""; String[] dashboardArray = null; if (params.containsKey(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN)) { dashboardArray = params.get(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DASHBOARD_NAME)) { dashboardArray = params.get(MetricRowMapper.METRIC_MODULE_DASHBOARD_NAME); } if (dashboardArray != null && dashboardArray.length > 0) { dashboard = dashboardArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN + " = ? "; needAnd = true; args.add(dashboard); argTypes.add(Types.VARCHAR); } String type = ""; String[] typeArray = null; if (params.containsKey(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN)) { typeArray = params.get(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_REF_ID_TYPE)) { typeArray = params.get(MetricRowMapper.METRIC_MODULE_REF_ID_TYPE); } if (typeArray != null && typeArray.length > 0) { type = typeArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN + " = ? "; needAnd = true; args.add(type); argTypes.add(Types.VARCHAR); } String grain = ""; String[] grainArray = null; if (params.containsKey(MetricRowMapper.METRIC_GRAIN_COLUMN)) { grainArray = params.get(MetricRowMapper.METRIC_GRAIN_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_GRAIN)) { grainArray = params.get(MetricRowMapper.METRIC_MODULE_GRAIN); } if (grainArray != null && grainArray.length > 0) { grain = grainArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_GRAIN_COLUMN + " = ? "; needAnd = true; args.add(grain); argTypes.add(Types.VARCHAR); } String formula = ""; String[] formulaArray = null; if (params.containsKey(MetricRowMapper.METRIC_FORMULA_COLUMN)) { formulaArray = params.get(MetricRowMapper.METRIC_FORMULA_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_FORMULA)) { formulaArray = params.get(MetricRowMapper.METRIC_MODULE_FORMULA); } if (formulaArray != null && formulaArray.length > 0) { formula = formulaArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_FORMULA_COLUMN + " = ? "; needAnd = true; args.add(formula); argTypes.add(Types.VARCHAR); } String displayFactorString = ""; Double displayFactor = 0.0; String[] displayFactorArray = null; if (params.containsKey(MetricRowMapper.METRIC_DISPLAY_FACTOR_COLUMN)) { displayFactorArray = params.get(MetricRowMapper.METRIC_DISPLAY_FACTOR_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR)) { displayFactorArray = params.get(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR); } if (displayFactorArray != null && displayFactorArray.length > 0) { displayFactorString = displayFactorArray[0]; try { displayFactor = Double.parseDouble(displayFactorString); if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_DISPLAY_FACTOR_COLUMN + " = ? "; needAnd = true; args.add(displayFactor); argTypes.add(Types.DECIMAL); } catch (NumberFormatException e) { Logger.error("MetricDAO updateMetricValues wrong page parameter. Error message: " + e.getMessage()); displayFactor = 0.0; } } String displayFactorSym = ""; String[] factorSymArray = null; if (params.containsKey(MetricRowMapper.METRIC_DISPLAY_FACTOR_SYM_COLUMN)) { factorSymArray = params.get(MetricRowMapper.METRIC_DISPLAY_FACTOR_SYM_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR_SYM)) { factorSymArray = params.get(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR_SYM); } if (factorSymArray != null && factorSymArray.length > 0) { displayFactorSym = factorSymArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_DISPLAY_FACTOR_SYM_COLUMN + " = ? "; needAnd = true; args.add(displayFactorSym); argTypes.add(Types.VARCHAR); } String groupSkString = ""; Integer groupSk = 0; String[] groupSkArray = null; if (params.containsKey(MetricRowMapper.METRIC_SUB_CATEGORY_COLUMN)) { groupSkArray = params.get(MetricRowMapper.METRIC_SUB_CATEGORY_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_SUB_CATEGORY)) { groupSkArray = params.get(MetricRowMapper.METRIC_MODULE_SUB_CATEGORY); } if (groupSkArray != null && groupSkArray.length > 0) { groupSkString = groupSkArray[0]; try { groupSk = Integer.parseInt(groupSkString); if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_SUB_CATEGORY_COLUMN + " = ? "; needAnd = true; args.add(groupSk); argTypes.add(Types.INTEGER); } catch (NumberFormatException e) { Logger.error("MetricDAO updateMetricValues wrong page parameter. Error message: " + e.getMessage()); groupSk = 0; } } String metricSource = ""; String[] metricSourceArray = null; if (params.containsKey(MetricRowMapper.METRIC_SOURCE_COLUMN)) { metricSourceArray = params.get(MetricRowMapper.METRIC_SOURCE_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_SOURCE)) { metricSourceArray = params.get(MetricRowMapper.METRIC_MODULE_SOURCE); } if (metricSourceArray != null && metricSourceArray.length > 0) { metricSource = metricSourceArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_SOURCE_COLUMN + " = ? "; needAnd = true; args.add(metricSource); argTypes.add(Types.VARCHAR); } if (StringUtils.isNotBlank(setClause)) { args.add(id); argTypes.add(Types.SMALLINT); int row = getJdbcTemplate().update(UPDATE_METRIC.replace("$SET_CLAUSE", setClause), args.toArray(), Ints.toArray(argTypes)); if (row > 0) { message = ""; } } else { message = "Wrong post body"; } return message; }
From source file:com.alibaba.otter.shared.common.utils.meta.DdlUtils.java
private static Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = new Column(); column.setName((String) values.get("COLUMN_NAME")); column.setDefaultValue((String) values.get("COLUMN_DEF")); column.setTypeCode(((Integer) values.get("DATA_TYPE")).intValue()); String typeName = (String) values.get("TYPE_NAME"); // column.setType(typeName); if ((typeName != null) && typeName.startsWith("TIMESTAMP")) { column.setTypeCode(Types.TIMESTAMP); }//w w w. jav a 2 s .c om // modify 2013-09-25?unsigned if ((typeName != null) && StringUtils.containsIgnoreCase(typeName, "UNSIGNED")) { // unsigned???? switch (column.getTypeCode()) { case Types.TINYINT: column.setTypeCode(Types.SMALLINT); break; case Types.SMALLINT: column.setTypeCode(Types.INTEGER); break; case Types.INTEGER: column.setTypeCode(Types.BIGINT); break; case Types.BIGINT: column.setTypeCode(Types.DECIMAL); break; default: break; } } Integer precision = (Integer) values.get("NUM_PREC_RADIX"); if (precision != null) { column.setPrecisionRadix(precision.intValue()); } String size = (String) values.get("COLUMN_SIZE"); if (size == null) { size = (String) _defaultSizes.get(new Integer(column.getTypeCode())); } // we're setting the size after the precision and radix in case // the database prefers to return them in the size value column.setSize(size); int scale = 0; Object dec_digits = values.get("DECIMAL_DIGITS"); if (dec_digits instanceof String) { scale = (dec_digits == null) ? 0 : NumberUtils.toInt(dec_digits.toString()); } else if (dec_digits instanceof Integer) { scale = (dec_digits == null) ? 0 : (Integer) dec_digits; } if (scale != 0) { column.setScale(scale); } column.setRequired("NO".equalsIgnoreCase(((String) values.get("IS_NULLABLE")).trim())); column.setDescription((String) values.get("REMARKS")); return column; }
From source file:org.h2gis.drivers.geojson.GeoJsonWriteDriver.java
/** * Return true is the SQL type is supported by the GeoJSON driver. * * @param sqlTypeId//ww w .ja va2 s . com * @param sqlTypeName * @return * @throws SQLException */ public boolean isSupportedPropertyType(int sqlTypeId, String sqlTypeName) throws SQLException { switch (sqlTypeId) { case Types.BOOLEAN: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.BIGINT: case Types.SMALLINT: case Types.DATE: case Types.VARCHAR: case Types.NCHAR: case Types.CHAR: return true; default: throw new SQLException("Field type not supported by GeoJSON driver: " + sqlTypeName); } }
From source file:com.cloudera.sqoop.manager.SqlManager.java
/** * Resolve a database-specific type to the Java type that should contain it. * @param sqlType/* w w w . j a va 2s . c o m*/ * @return the name of a Java type to hold the sql datatype, or null if none. */ public String toJavaType(int sqlType) { // Mappings taken from: // http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html if (sqlType == Types.INTEGER) { return "Integer"; } else if (sqlType == Types.VARCHAR) { return "String"; } else if (sqlType == Types.CHAR) { return "String"; } else if (sqlType == Types.LONGVARCHAR) { return "String"; } else if (sqlType == Types.NUMERIC) { return "java.math.BigDecimal"; } else if (sqlType == Types.DECIMAL) { return "java.math.BigDecimal"; } else if (sqlType == Types.BIT) { return "Boolean"; } else if (sqlType == Types.BOOLEAN) { return "Boolean"; } else if (sqlType == Types.TINYINT) { return "Integer"; } else if (sqlType == Types.SMALLINT) { return "Integer"; } else if (sqlType == Types.BIGINT) { return "Long"; } else if (sqlType == Types.REAL) { return "Float"; } else if (sqlType == Types.FLOAT) { return "Double"; } else if (sqlType == Types.DOUBLE) { return "Double"; } else if (sqlType == Types.DATE) { return "java.sql.Date"; } else if (sqlType == Types.TIME) { return "java.sql.Time"; } else if (sqlType == Types.TIMESTAMP) { return "java.sql.Timestamp"; } else if (sqlType == Types.BINARY || sqlType == Types.VARBINARY) { return BytesWritable.class.getName(); } else if (sqlType == Types.CLOB) { return ClobRef.class.getName(); } else if (sqlType == Types.BLOB || sqlType == Types.LONGVARBINARY) { return BlobRef.class.getName(); } else { // TODO(aaron): Support DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT. // Return null indicating database-specific manager should return a // java data type if it can find one for any nonstandard type. return null; } }
From source file:org.apache.empire.db.codegen.CodeGenParser.java
/** * converts a SQL DataType to a EmpireDataType *///from www.ja v a 2 s .co m private DataType getEmpireDataType(int sqlType) { DataType empireType = DataType.UNKNOWN; switch (sqlType) { case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: case Types.BIGINT: empireType = DataType.INTEGER; break; case Types.VARCHAR: empireType = DataType.TEXT; break; case Types.DATE: empireType = DataType.DATE; break; case Types.TIMESTAMP: case Types.TIME: empireType = DataType.DATETIME; break; case Types.CHAR: empireType = DataType.CHAR; break; case Types.DOUBLE: case Types.FLOAT: case Types.REAL: empireType = DataType.FLOAT; break; case Types.DECIMAL: case Types.NUMERIC: empireType = DataType.DECIMAL; break; case Types.BIT: case Types.BOOLEAN: empireType = DataType.BOOL; break; case Types.CLOB: case Types.LONGVARCHAR: empireType = DataType.CLOB; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: empireType = DataType.BLOB; break; default: empireType = DataType.UNKNOWN; log.warn("SQL column type " + sqlType + " not supported."); } log.debug("Mapping date type " + String.valueOf(sqlType) + " to " + empireType); return empireType; }