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.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: String string = rs.getString(index); if (column.getType() == ColumnType.BLOBID && string != null) { return column.getModel().getBinary(string); } else {/* w ww . j a va 2s . c o m*/ return string; } 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: Timestamp ts = rs.getTimestamp(index); if (ts == null) { return null; } else { Serializable cal = new GregorianCalendar(); // XXX timezone ((Calendar) cal).setTimeInMillis(ts.getTime()); return cal; } case Types.ARRAY: return (Serializable) rs.getArray(index).getArray(); } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING:// w ww.jav a2 s . c o m if (type.isUnconstrained()) { return jdbcInfo("varchar", Types.VARCHAR); } else if (type.isClob()) { return jdbcInfo("text", Types.CLOB); } else { return jdbcInfo("varchar(%d)", type.length, Types.VARCHAR); } case ARRAY_STRING: if (type.isUnconstrained()) { return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR); } else if (type.isClob()) { return jdbcInfo("text[]", Types.ARRAY, "text", Types.CLOB); } else { return jdbcInfo("varchar(%d)[]", type.length, Types.ARRAY, "varchar", Types.VARCHAR); } case BOOLEAN: return jdbcInfo("bool", Types.BIT); case ARRAY_BOOLEAN: return jdbcInfo("bool[]", Types.ARRAY, "bool", Types.BOOLEAN); case LONG: return jdbcInfo("int8", Types.BIGINT); case ARRAY_LONG: return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT); case DOUBLE: return jdbcInfo("float8", Types.DOUBLE); case ARRAY_DOUBLE: return jdbcInfo("float8[]", Types.ARRAY, "float8", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("timestamp", Types.TIMESTAMP); case ARRAY_TIMESTAMP: return jdbcInfo("timestamp[]", Types.ARRAY, "timestamp", Types.TIMESTAMP); case BLOBID: return jdbcInfo("varchar(40)", Types.VARCHAR); case ARRAY_BLOBID: return jdbcInfo("varchar(40)[]", Types.ARRAY, "varchar", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: switch (idType) { case VARCHAR: return jdbcInfo("varchar(36)", Types.VARCHAR); case UUID: return jdbcInfo("uuid", Types.OTHER); case SEQUENCE: return jdbcInfo("int8", Types.BIGINT); } case NODEARRAY: switch (idType) { case VARCHAR: return jdbcInfo("varchar(36)[]", Types.ARRAY, "varchar", Types.VARCHAR); case UUID: return jdbcInfo("uuid[]", Types.ARRAY, "uuid", Types.OTHER); case SEQUENCE: return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT); } case SYSNAME: return jdbcInfo("varchar(250)", Types.VARCHAR); case SYSNAMEARRAY: return jdbcInfo("varchar(250)[]", Types.ARRAY, "varchar", Types.VARCHAR); case TINYINT: return jdbcInfo("int2", Types.SMALLINT); case INTEGER: return jdbcInfo("int4", Types.INTEGER); case ARRAY_INTEGER: return jdbcInfo("int4[]", Types.ARRAY, "int4", Types.INTEGER); case AUTOINC: return jdbcInfo("serial", Types.INTEGER); case FTINDEXED: if (compatibilityFulltextTable) { return jdbcInfo("tsvector", Types.OTHER); } else { return jdbcInfo("text", Types.CLOB); } case FTSTORED: if (compatibilityFulltextTable) { return jdbcInfo("tsvector", Types.OTHER); } else { return jdbcInfo("text", Types.CLOB); } case CLUSTERNODE: return jdbcInfo("int4", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { 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 getFromResultSetTimestamp(rs, index, column); case Types.ARRAY: Array array = rs.getArray(index); return array == null ? null : (Serializable) array.getArray(); }/* ww w . j a v a 2s .c o m*/ throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.apache.cayenne.migration.MigrationGenerator.java
protected String nameForJdbcType(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.DATE: return "date"; case Types.DECIMAL: return "decimal"; case Types.DOUBLE: return "double"; case Types.FLOAT: return "float"; case Types.INTEGER: return "integer"; case Types.LONGVARBINARY: return "longVarBinary"; case Types.LONGVARCHAR: return "longVarChar"; case Types.NUMERIC: return "numeric"; case Types.REAL: return "real"; case Types.SMALLINT: return "smallInt"; 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:// w w w . jav a 2s .co m return null; } }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: return getFromResultSetString(rs, index, column); case Types.CLOB: // Oracle cannot read CLOBs using rs.getString when the ResultSet is // a ScrollableResultSet (the standard OracleResultSetImpl works // fine). Reader r = rs.getCharacterStream(index); if (r == null) { return null; }/*www. ja v a 2 s . c o m*/ StringBuilder sb = new StringBuilder(); try { int n; char[] buffer = new char[4096]; while ((n = r.read(buffer)) != -1) { sb.append(new String(buffer, 0, n)); } } catch (IOException e) { log.error("Cannot read CLOB", e); } return sb.toString(); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getFromResultSetTimestamp(rs, index, column); } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.pentaho.metadata.util.SQLModelGenerator.java
private static DataType converDataType(int type) { switch (type) { case Types.FLOAT: case Types.BIT: case Types.DOUBLE: case Types.SMALLINT: case Types.REAL: case Types.DECIMAL: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: return DataType.NUMERIC; case Types.BINARY: case Types.CLOB: case Types.BLOB: return DataType.BINARY; case Types.BOOLEAN: return DataType.BOOLEAN; case Types.DATE: return DataType.DATE; case Types.TIMESTAMP: return DataType.DATE; case Types.LONGVARCHAR: case Types.VARCHAR: return DataType.STRING; default:// w w w . ja v a 2 s . c o m return DataType.UNKNOWN; } }
From source file:com.squid.core.domain.operators.ExtendedType.java
/** * compute a type "order" that can be used to compare types and promote types. * The order is a couple (x,y), where x represent a family type (string,date,numbers) and y an order in that family * A type should be promoted to the higher order. * @return//from ww w . j av a 2s . c om */ public int[] computeTypeOrder() { switch (getDataType()) { case Types.BIT: return new int[] { NUMBER_ORDER, 0 }; case Types.BOOLEAN: return new int[] { NUMBER_ORDER, 1 }; case Types.TINYINT: return new int[] { NUMBER_ORDER, 2 }; case Types.SMALLINT: return new int[] { NUMBER_ORDER, 3 }; case Types.INTEGER: return new int[] { NUMBER_ORDER, 4 }; case Types.BIGINT: return new int[] { NUMBER_ORDER, 5 }; /////////////////////////// case Types.REAL: return new int[] { NUMBER_ORDER, 6 }; case Types.DOUBLE: case Types.FLOAT: return new int[] { NUMBER_ORDER, 7 }; case Types.DECIMAL: return new int[] { NUMBER_ORDER, 8 }; case Types.NUMERIC: return new int[] { NUMBER_ORDER, 9 }; ////////////////////////// case Types.CHAR: return new int[] { STRING_ORDER, 0 }; case Types.VARCHAR: return new int[] { STRING_ORDER, 1 }; case Types.LONGVARCHAR: return new int[] { STRING_ORDER, 2 }; case Types.CLOB: return new int[] { STRING_ORDER, 3 }; /////////////////////////// case Types.TIME: return new int[] { DATE_ORDER, 1 }; case Types.DATE: return new int[] { DATE_ORDER, 2 }; case Types.TIMESTAMP: return new int[] { DATE_ORDER, 3 }; case CustomTypes.INTERVAL: return new int[] { DATE_ORDER, 4 }; /////////////////////////// default: return new int[] { UNKNOWN_ORDER, 0 }; } }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectOracle.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: String string = rs.getString(index); if (column.getType() == ColumnType.BLOBID && string != null) { return column.getModel().getBinary(string); } else {//from www. j ava 2 s. c om return string; } case Types.CLOB: // Oracle cannot read CLOBs using rs.getString when the ResultSet is // a ScrollableResultSet (the standard OracleResultSetImpl works // fine). Reader r = rs.getCharacterStream(index); if (r == null) { return null; } StringBuilder sb = new StringBuilder(); char[] buffer = new char[4096]; try { int n; while ((n = r.read(buffer)) != -1) { sb.append(new String(buffer, 0, n)); } } catch (IOException e) { log.error("Cannot read CLOB", e); } return sb.toString(); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: Timestamp ts = rs.getTimestamp(index); if (ts == null) { return null; } else { Serializable cal = new GregorianCalendar(); // XXX timezone ((Calendar) cal).setTimeInMillis(ts.getTime()); return cal; } } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING:/* w ww. j a v a2s . co 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: switch (idType) { case VARCHAR: return jdbcInfo("VARCHAR2(36)", Types.VARCHAR); case SEQUENCE: return jdbcInfo("NUMBER(10,0)", Types.INTEGER); default: throw new AssertionError("Unknown id type: " + idType); } 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 AUTOINC: 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("VARCHAR(25)", Types.VARCHAR); case CLUSTERFRAGS: return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.apache.hadoop.sqoop.manager.SqlManager.java
public String toJavaType(int sqlType) { // mappings 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 {/*from ww w. j a va 2 s.com*/ // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY, // STRUCT, REF, JAVA_OBJECT. return null; } }