List of usage examples for java.sql Types BIT
int BIT
To view the source code for java.sql Types BIT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIT
.
From source file:org.apache.openjpa.jdbc.sql.H2Dictionary.java
@Override public int getPreferredType(int type) { if (type == Types.BIT) return Types.BOOLEAN; return type;/* w ww .j av a2 s .c o m*/ }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the {@link Types} constant for the given SQL type name. */// w w w . j a va2s . c o m public static int getJDBCType(String name) { if ("array".equalsIgnoreCase(name)) return Types.ARRAY; if ("bigint".equalsIgnoreCase(name)) return Types.BIGINT; if ("binary".equalsIgnoreCase(name)) return Types.BINARY; if ("bit".equalsIgnoreCase(name)) return Types.BIT; if ("blob".equalsIgnoreCase(name)) return Types.BLOB; if ("char".equalsIgnoreCase(name)) return Types.CHAR; if ("clob".equalsIgnoreCase(name)) return Types.CLOB; if ("date".equalsIgnoreCase(name)) return Types.DATE; if ("decimal".equalsIgnoreCase(name)) return Types.DECIMAL; if ("distinct".equalsIgnoreCase(name)) return Types.DISTINCT; if ("double".equalsIgnoreCase(name)) return Types.DOUBLE; if ("float".equalsIgnoreCase(name)) return Types.FLOAT; if ("integer".equalsIgnoreCase(name)) return Types.INTEGER; if ("java_object".equalsIgnoreCase(name)) return Types.JAVA_OBJECT; if ("longvarbinary".equalsIgnoreCase(name)) return Types.LONGVARBINARY; if ("longvarchar".equalsIgnoreCase(name)) return Types.LONGVARCHAR; if ("null".equalsIgnoreCase(name)) return Types.NULL; if ("numeric".equalsIgnoreCase(name)) return Types.NUMERIC; if ("other".equalsIgnoreCase(name)) return Types.OTHER; if ("real".equalsIgnoreCase(name)) return Types.REAL; if ("ref".equalsIgnoreCase(name)) return Types.REF; if ("smallint".equalsIgnoreCase(name)) return Types.SMALLINT; if ("struct".equalsIgnoreCase(name)) return Types.STRUCT; if ("time".equalsIgnoreCase(name)) return Types.TIME; if ("timestamp".equalsIgnoreCase(name)) return Types.TIMESTAMP; if ("tinyint".equalsIgnoreCase(name)) return Types.TINYINT; if ("varbinary".equalsIgnoreCase(name)) return Types.VARBINARY; if ("varchar".equalsIgnoreCase(name)) return Types.VARCHAR; if (name == null || name.toLowerCase().startsWith("unknown")) return Types.OTHER; throw new IllegalArgumentException("name = " + name); }
From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java
/** * ? ?//from w ww . ja va 2s . c om * * @param sqlType * @return */ public static boolean isNumberType(int sqlType) { switch (sqlType) { case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.NUMERIC: case Types.BIT: case Types.SMALLINT: case Types.TINYINT: return true; } return false; }
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;//w ww . j a v a 2 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.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING://w w w . ja va2 s . c o m if (type.isUnconstrained()) { return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR); } else if (type.isClob() || type.length > 2000) { return jdbcInfo("NCLOB", Types.CLOB); } else { return jdbcInfo("NVARCHAR2(%d)", type.length, Types.VARCHAR); } case BOOLEAN: return jdbcInfo("NUMBER(1,0)", Types.BIT); case LONG: return jdbcInfo("NUMBER(19,0)", Types.BIGINT); case DOUBLE: return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("TIMESTAMP", Types.TIMESTAMP); case BLOBID: return jdbcInfo("VARCHAR2(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: return jdbcInfo("VARCHAR2(36)", Types.VARCHAR); case SYSNAME: case SYSNAMEARRAY: return jdbcInfo("VARCHAR2(250)", Types.VARCHAR); case TINYINT: return jdbcInfo("NUMBER(3,0)", Types.TINYINT); case INTEGER: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case FTINDEXED: return jdbcInfo("CLOB", Types.CLOB); case FTSTORED: return jdbcInfo("NCLOB", Types.CLOB); case CLUSTERNODE: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectOracle.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type) { case VARCHAR: return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR); case CLOB:/*from w w w .j a v a 2 s.co m*/ return jdbcInfo("NCLOB", Types.CLOB); case BOOLEAN: return jdbcInfo("NUMBER(1,0)", Types.BIT); case LONG: return jdbcInfo("NUMBER(19,0)", Types.BIGINT); case DOUBLE: return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("TIMESTAMP", Types.TIMESTAMP); case BLOBID: return jdbcInfo("VARCHAR2(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEVAL: return jdbcInfo("VARCHAR2(36)", Types.VARCHAR); case SYSNAME: return jdbcInfo("VARCHAR2(250)", Types.VARCHAR); case TINYINT: return jdbcInfo("NUMBER(3,0)", Types.TINYINT); case INTEGER: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case FTINDEXED: return jdbcInfo("CLOB", Types.CLOB); case FTSTORED: return jdbcInfo("NCLOB", Types.CLOB); case CLUSTERNODE: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.apache.ddlutils.platform.sybase.SybasePlatform.java
/** * Creates a new platform instance.//from ww w . j a va 2 s . c o m */ public SybasePlatform() { PlatformInfo info = getPlatformInfo(); info.setMaxIdentifierLength(28); info.setNullAsDefaultValueRequired(true); info.setIdentityColumnAutomaticallyRequired(true); info.setMultipleIdentityColumnsSupported(false); info.setPrimaryKeyColumnsHaveToBeRequired(true); info.setCommentPrefix("/*"); info.setCommentSuffix("*/"); info.addNativeTypeMapping(Types.ARRAY, "IMAGE"); // BIGINT is mapped back in the model reader info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)"); // we're not using the native BIT type because it is rather limited (cannot be NULL, cannot be indexed) info.addNativeTypeMapping(Types.BIT, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION"); info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE); info.addNativeTypeMapping(Types.INTEGER, "INT"); info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT"); info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.setDefaultSize(Types.BINARY, 254); info.setDefaultSize(Types.VARBINARY, 254); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); setSqlBuilder(new SybaseBuilder(this)); setModelReader(new SybaseModelReader(this)); }
From source file:org.apache.sqoop.manager.ConnManager.java
/** * Resolve a database-specific type to the Java type that should contain it. * @param sqlType sql type/*from w ww.j a va2 s .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.NVARCHAR) { return "String"; } else if (sqlType == Types.NCHAR) { return "String"; } else if (sqlType == Types.LONGNVARCHAR) { 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.ddlutils.platform.mssql.MSSqlPlatform.java
/** * Creates a new platform instance.// w ww. ja v a 2s.c o m */ public MSSqlPlatform() { PlatformInfo info = getPlatformInfo(); info.setMaxIdentifierLength(128); info.setPrimaryKeyColumnAutomaticallyRequired(true); info.setIdentityColumnAutomaticallyRequired(true); info.setMultipleIdentityColumnsSupported(false); info.setSupportedOnUpdateActions( new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE }); info.addEquivalentOnUpdateActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT); info.setSupportedOnDeleteActions( new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE }); info.addEquivalentOnDeleteActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT); info.addNativeTypeMapping(Types.ARRAY, "IMAGE", Types.LONGVARBINARY); // BIGINT will be mapped back to BIGINT by the model reader info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)"); info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "BIT", Types.BIT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "FLOAT", Types.FLOAT); info.addNativeTypeMapping(Types.INTEGER, "INT"); info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT"); info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME"); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); info.setDefaultSize(Types.BINARY, 254); info.setDefaultSize(Types.VARBINARY, 254); setSqlBuilder(new MSSqlBuilder(this)); setModelReader(new MSSqlModelReader(this)); }
From source file:org.apache.ddlutils.platform.oracle.Oracle8ModelReader.java
/** * {@inheritDoc}/* w w w . j av a 2s. co m*/ */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getDefaultValue() != null) { // Oracle pads the default value with spaces column.setDefaultValue(column.getDefaultValue().trim()); } if (column.getTypeCode() == Types.DECIMAL) { // We're back-mapping the NUMBER columns returned by Oracle // Note that the JDBC driver returns DECIMAL for these NUMBER columns switch (column.getSizeAsInt()) { case 1: if (column.getScale() == 0) { column.setTypeCode(Types.BIT); } break; case 3: if (column.getScale() == 0) { column.setTypeCode(Types.TINYINT); } break; case 5: if (column.getScale() == 0) { column.setTypeCode(Types.SMALLINT); } break; case 18: column.setTypeCode(Types.REAL); break; case 22: if (column.getScale() == 0) { column.setTypeCode(Types.INTEGER); } break; case 38: if (column.getScale() == 0) { column.setTypeCode(Types.BIGINT); } else { column.setTypeCode(Types.DOUBLE); } break; } } else if (column.getTypeCode() == Types.FLOAT) { // Same for REAL, FLOAT, DOUBLE PRECISION, which all back-map to FLOAT but with // different sizes (63 for REAL, 126 for FLOAT/DOUBLE PRECISION) switch (column.getSizeAsInt()) { case 63: column.setTypeCode(Types.REAL); break; case 126: column.setTypeCode(Types.DOUBLE); break; } } else if ((column.getTypeCode() == Types.DATE) || (column.getTypeCode() == Types.TIMESTAMP)) { // Oracle has only one DATE/TIME type, so we can't know which it is and thus map // it back to TIMESTAMP column.setTypeCode(Types.TIMESTAMP); // we also reverse the ISO-format adaptation, and adjust the default value to timestamp if (column.getDefaultValue() != null) { Matcher matcher = _oracleIsoTimestampPattern.matcher(column.getDefaultValue()); Timestamp timestamp = null; if (matcher.matches()) { String timestampVal = matcher.group(1); timestamp = Timestamp.valueOf(timestampVal); } else { matcher = _oracleIsoDatePattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String dateVal = matcher.group(1); timestamp = new Timestamp(Date.valueOf(dateVal).getTime()); } else { matcher = _oracleIsoTimePattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String timeVal = matcher.group(1); timestamp = new Timestamp(Time.valueOf(timeVal).getTime()); } } } if (timestamp != null) { column.setDefaultValue(timestamp.toString()); } } } else if (TypeMap.isTextType(column.getTypeCode())) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); } return column; }