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:com.nabla.wapp.server.json.SqlColumn.java
public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException { switch (type) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: record.put(label, rs.getInt(column)); break;//from ww w . j a v a 2 s. c om case Types.BOOLEAN: case Types.BIT: record.put(label, rs.getBoolean(column)); break; case Types.DATE: final Date dt = rs.getDate(column); if (rs.wasNull()) record.put(label, null); else record.put(label, new JSonDate(dt)); return; case Types.TIMESTAMP: final Timestamp tm = rs.getTimestamp(column); if (rs.wasNull()) record.put(label, null); else record.put(label, timeStampFormat.format(tm)); return; case Types.DOUBLE: record.put(label, rs.getDouble(column)); break; case Types.FLOAT: record.put(label, rs.getFloat(column)); break; case Types.NULL: record.put(label, null); return; default: record.put(label, rs.getString(column)); break; } if (rs.wasNull()) record.put(label, null); }
From source file:org.jumpmind.db.platform.h2.H2DdlBuilder.java
public H2DdlBuilder() { super(DatabaseNamesConstants.H2); databaseInfo.setNonPKIdentityColumnsSupported(false); databaseInfo.setIdentityOverrideAllowed(false); databaseInfo.setSystemForeignKeyIndicesAlwaysNonUnique(true); databaseInfo.setNullAsDefaultValueRequired(false); databaseInfo.addNativeTypeMapping(Types.ARRAY, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.DISTINCT, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.NULL, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.REF, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.STRUCT, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.DATALINK, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.BIT, "BOOLEAN", Types.BIT); databaseInfo.addNativeTypeMapping(Types.NUMERIC, "DECIMAL", Types.DECIMAL); databaseInfo.addNativeTypeMapping(Types.BINARY, "BINARY", Types.BINARY); databaseInfo.addNativeTypeMapping(Types.BLOB, "BLOB", Types.BLOB); databaseInfo.addNativeTypeMapping(Types.CLOB, "CLOB", Types.CLOB); databaseInfo.addNativeTypeMapping(Types.LONGVARCHAR, "VARCHAR(" + Integer.MAX_VALUE + ")", Types.VARCHAR); databaseInfo.addNativeTypeMapping(Types.FLOAT, "DOUBLE", Types.DOUBLE); databaseInfo.addNativeTypeMapping(Types.JAVA_OBJECT, "OTHER"); databaseInfo.setDefaultSize(Types.CHAR, Integer.MAX_VALUE); databaseInfo.setDefaultSize(Types.VARCHAR, Integer.MAX_VALUE); databaseInfo.setDefaultSize(Types.BINARY, Integer.MAX_VALUE); databaseInfo.setDefaultSize(Types.VARBINARY, Integer.MAX_VALUE); databaseInfo.setNonBlankCharColumnSpacePadded(false); databaseInfo.setBlankCharColumnSpacePadded(false); databaseInfo.setCharColumnSpaceTrimmed(true); databaseInfo.setEmptyStringNulled(false); databaseInfo.setNullAsDefaultValueRequired(true); }
From source file:com.squid.core.jdbc.vendor.sqlserver.SQLServerJDBCDataFormatter.java
@Override public String formatJDBCObject(final Object column, final int colType) throws SQLException { if (column == null) { return ""; }/*from w w w. j ava 2 s . co m*/ switch (colType) { case -9: //NVARCHAR case -15: //NCHAR case Types.BIT: return super.formatJDBCObject(this.unboxJDBCObject(column, colType), java.sql.Types.VARCHAR); } return super.formatJDBCObject(column, colType); }
From source file:com.tesora.dve.common.TestDataGenerator.java
protected Object getColumnValue(ColumnMetadata cm) { Object cv = null;/*from ww w .j av a 2 s .co m*/ Calendar cal = Calendar.getInstance(); switch (cm.getDataType()) { case Types.BIT: case Types.BOOLEAN: cv = Boolean.TRUE; break; case Types.BIGINT: cv = Long.MAX_VALUE; break; case Types.CHAR: case Types.VARCHAR: cv = StringUtils.left(baseString, cm.getSize()); break; case Types.SMALLINT: cv = Short.MAX_VALUE; break; case Types.TINYINT: cv = Byte.MAX_VALUE; break; case Types.INTEGER: cv = Integer.MAX_VALUE; break; case Types.DOUBLE: cv = new Double(1234.5678); // TODO need to handle s,p break; case Types.FLOAT: cv = new Float(123.56); // TODO need to handle s,p break; case Types.DECIMAL: cv = new BigDecimal("12345.6789"); // TODO need to handle s,p break; case Types.DATE: cal.setTimeInMillis(123456789); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cv = cal.getTime(); break; case Types.TIMESTAMP: cal.setTimeInMillis(123456789); cv = cal.getTime(); break; case Types.TIME: cv = new Time(123456789); break; default: break; } return cv; }
From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java
public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException { String value = ""; switch (colType) { case Types.BIT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); }/*w w w. j ava 2 s.c o m*/ break; case Types.BOOLEAN: if (jdbcObject != null) { value = new Boolean(jdbcObject.toString()).toString(); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.CLOB: if (jdbcObject != null) { try { value = read((Clob) jdbcObject); } catch (SQLException sqle) { value = ""; } catch (IOException ioe) { value = ""; } } break; case Types.ARRAY: try { ResultSet rs = ((Array) jdbcObject).getResultSet(); int arrayType = ((Array) jdbcObject).getBaseType(); boolean isNotNew = false; while (rs.next()) { String current = formatJDBCObject(rs.getObject(2), arrayType); if ("".equals(current.trim()) == false) { if (isNotNew) { value = value + ","; } else { isNotNew = !isNotNew; } value = value + current; } } if ("".equals(value) == false) { value = "{" + value + "}"; } } catch (SQLException sqle) { value = ""; } break; case Types.JAVA_OBJECT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); } break; case Types.DATE: if (jdbcObject != null) { value = formatter.formatDate(jdbcObject); } break; case Types.TIME: if (jdbcObject != null) { value = ((Time) jdbcObject).toString(); } break; case Types.TIMESTAMP: if (jdbcObject != null) { value = formatter.formatTimestamp(jdbcObject); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: if (jdbcObject != null) { value = jdbcObject.toString(); } else { value = "NULL"; } break; case Types.BINARY: value = new String((byte[]) jdbcObject); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING://w ww.j a v a2 s.com if (type.isUnconstrained()) { return jdbcInfo("VARCHAR(255)", Types.VARCHAR); } else if (type.isClob() || type.length > 2000) { return jdbcInfo("CLOB", Types.CLOB); } else { return jdbcInfo("VARCHAR(%d)", type.length, Types.VARCHAR); } case BOOLEAN: return jdbcInfo("SMALLINT", Types.BIT); case LONG: return jdbcInfo("BIGINT", Types.BIGINT); case DOUBLE: return jdbcInfo("DOUBLE", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("TIMESTAMP", Types.TIMESTAMP); case BLOBID: return jdbcInfo("VARCHAR(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: return jdbcInfo("VARCHAR(36)", Types.VARCHAR); case SYSNAME: case SYSNAMEARRAY: return jdbcInfo("VARCHAR(250)", Types.VARCHAR); case TINYINT: return jdbcInfo("SMALLINT", Types.TINYINT); case INTEGER: return jdbcInfo("INTEGER", Types.INTEGER); case AUTOINC: return jdbcInfo("INTEGER", Types.INTEGER); // TODO case FTINDEXED: return jdbcInfo("CLOB", Types.CLOB); case FTSTORED: return jdbcInfo("CLOB", Types.CLOB); case CLUSTERNODE: return jdbcInfo("VARCHAR(25)", Types.VARCHAR); case CLUSTERFRAGS: return jdbcInfo("VARCHAR(4000)", Types.VARCHAR); default: throw new AssertionError(type); } }
From source file:org.apache.kylin.jdbc.KylinClient.java
@SuppressWarnings("rawtypes") public static Class convertType(int sqlType) { Class result = Object.class; switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: result = String.class; break;/*ww w. j a va 2 s. co m*/ case Types.NUMERIC: case Types.DECIMAL: result = BigDecimal.class; break; case Types.BIT: result = Boolean.class; break; case Types.TINYINT: result = Byte.class; break; case Types.SMALLINT: result = Short.class; break; case Types.INTEGER: result = Integer.class; break; case Types.BIGINT: result = Long.class; break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: result = Double.class; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: result = Byte[].class; break; case Types.DATE: result = Date.class; break; case Types.TIME: result = Time.class; break; case Types.TIMESTAMP: result = Timestamp.class; break; default: //do nothing break; } return result; }
From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java
/** * Creates a new platform instance./*w w w .j av a 2 s . c o m*/ */ public PostgreSqlPlatform() { PlatformInfo info = getPlatformInfo(); info.setPrimaryKeyColumnAutomaticallyRequired(true); // this is the default length though it might be changed when building PostgreSQL // in file src/include/postgres_ext.h info.setMaxIdentifierLength(31); info.addNativeTypeMapping(Types.ARRAY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BINARY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BIT, "BOOLEAN"); info.addNativeTypeMapping(Types.BLOB, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "BOOLEAN", Types.BIT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DECIMAL, "NUMERIC", Types.NUMERIC); info.addNativeTypeMapping(Types.DISTINCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION"); info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE); info.addNativeTypeMapping(Types.JAVA_OBJECT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.NULL, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.VARBINARY, "BYTEA", Types.LONGVARBINARY); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); // no support for specifying the size for these types (because they are mapped // to BYTEA which back-maps to BLOB) info.setHasSize(Types.BINARY, false); info.setHasSize(Types.VARBINARY, false); setSqlBuilder(new PostgreSqlBuilder(this)); setModelReader(new PostgreSqlModelReader(this)); }
From source file:org.apache.ddlutils.platform.DefaultValueHelper.java
/** * Converts a boolean default value to the given target type. * //from www . j a v a2 s . com * @param defaultValue The default value * @param targetTypeCode The target type code * @return The converted value */ private Object convertBoolean(String defaultValue, int targetTypeCode) { Boolean value = null; Object result = null; try { value = (Boolean) ConvertUtils.convert(defaultValue, Boolean.class); } catch (ConversionException ex) { return defaultValue; } if ((targetTypeCode == Types.BIT) || (targetTypeCode == Types.BOOLEAN)) { result = value; } else if (TypeMap.isNumericType(targetTypeCode)) { result = (value.booleanValue() ? new Integer(1) : new Integer(0)); } else { result = value.toString(); } return result; }
From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits./*ww w . jav a2s . c o m*/ */ protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }