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.ojb.broker.metadata.FieldTypeClasses.java
/** * Returns a {@link FieldType} instance for the given sql type * (see {@link java.sql.Types}) as specified in JDBC 3.0 specification * (see JDBC 3.0 specification <em>Appendix B, Data Type Conversion Tables</em>). * * @param jdbcType Specify the type to look for. * @return A new specific {@link FieldType} instance. *//*from w ww . j a va 2 s. c om*/ static FieldType newFieldType(JdbcType jdbcType) { FieldType result = null; switch (jdbcType.getType()) { case Types.ARRAY: result = new ArrayFieldType(); break; case Types.BIGINT: result = new LongFieldType(); break; case Types.BINARY: result = new ByteArrayFieldType(); break; case Types.BIT: result = new BooleanFieldType(); break; case Types.BLOB: result = new BlobFieldType(); break; case Types.CHAR: result = new StringFieldType(); break; case Types.CLOB: result = new ClobFieldType(); break; case Types.DATE: result = new DateFieldType(); break; case Types.DECIMAL: result = new BigDecimalFieldType(); break; // Not needed, user have to use the underlying sql datatype in OJB mapping files // case Types.DISTINCT: // result = new DistinctFieldType(); // break; case Types.DOUBLE: result = new DoubleFieldType(); break; case Types.FLOAT: result = new FloatFieldType(); break; case Types.INTEGER: result = new IntegerFieldType(); break; case Types.JAVA_OBJECT: result = new JavaObjectFieldType(); break; case Types.LONGVARBINARY: result = new ByteArrayFieldType(); break; case Types.LONGVARCHAR: result = new StringFieldType(); break; case Types.NUMERIC: result = new BigDecimalFieldType(); break; case Types.REAL: result = new FloatFieldType(); break; case Types.REF: result = new RefFieldType(); break; case Types.SMALLINT: result = new ShortFieldType(); break; case Types.STRUCT: result = new StructFieldType(); break; case Types.TIME: result = new TimeFieldType(); break; case Types.TIMESTAMP: result = new TimestampFieldType(); break; case Types.TINYINT: result = new ByteFieldType(); break; case Types.VARBINARY: result = new ByteArrayFieldType(); break; case Types.VARCHAR: result = new StringFieldType(); break; case Types.OTHER: result = new JavaObjectFieldType(); break; // // case Types.NULL: // result = new NullFieldType(); // break; //#ifdef JDBC30 case Types.BOOLEAN: result = new BooleanFieldType(); break; case Types.DATALINK: result = new URLFieldType(); break; //#endif default: throw new OJBRuntimeException("Unkown or not supported field type specified, specified jdbc type was '" + jdbcType + "', as string: " + JdbcTypesHelper.getSqlTypeAsString(jdbcType.getType())); } // make sure that the sql type was set result.setSqlType(jdbcType); return result; }
From source file:org.apache.ddlutils.io.converters.NumberConverter.java
/** * {@inheritDoc}//from w w w .j a v a2 s.com */ public Object convertFromString(String textRep, int sqlTypeCode) throws ConversionException { if (textRep == null) { return null; } else { Class targetClass = null; switch (sqlTypeCode) { case Types.BIGINT: targetClass = Long.class; break; case Types.BIT: case Types.BOOLEAN: targetClass = Boolean.class; break; case Types.DECIMAL: case Types.NUMERIC: targetClass = BigDecimal.class; break; case Types.DOUBLE: case Types.FLOAT: targetClass = Double.class; break; case Types.INTEGER: targetClass = Integer.class; break; case Types.REAL: targetClass = Float.class; break; case Types.SMALLINT: case Types.TINYINT: targetClass = Short.class; break; } return targetClass == null ? textRep : ConvertUtils.convert(textRep, targetClass); } }
From source file:com.nabla.wapp.server.json.SqlColumn.java
public SqlColumn(String label, int type, int length) { this.label = label; this.type = (type == Types.TINYINT) ? (length == 1 ? Types.BOOLEAN : type) : type; if (log.isDebugEnabled()) { String s;/*from w ww.jav a 2 s . co m*/ switch (this.type) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: s = "INTEGER"; break; case Types.BOOLEAN: case Types.BIT: s = "BOOLEAN"; break; case Types.DATE: s = "DATE"; break; case Types.TIMESTAMP: s = "TIMESTAMP"; break; case Types.DOUBLE: s = "DOUBLE"; break; case Types.FLOAT: s = "FLOAT"; break; case Types.NULL: s = "NULL"; break; default: s = "STRING"; break; } log.debug("column '" + this.label + "' " + s); } }
From source file:org.apache.ddlutils.platform.DefaultValueHelper.java
/** * Converts the given default value from the specified original to the target * jdbc type./*from w ww. j a va 2 s. c o m*/ * * @param defaultValue The default value * @param originalTypeCode The original type code * @param targetTypeCode The target type code * @return The converted default value */ public String convert(String defaultValue, int originalTypeCode, int targetTypeCode) { String result = defaultValue; if (defaultValue != null) { switch (originalTypeCode) { case Types.BIT: case Types.BOOLEAN: result = convertBoolean(defaultValue, targetTypeCode).toString(); break; case Types.DATE: if (targetTypeCode == Types.TIMESTAMP) { try { Date date = Date.valueOf(result); return new Timestamp(date.getTime()).toString(); } catch (IllegalArgumentException ex) { } } break; case Types.TIME: if (targetTypeCode == Types.TIMESTAMP) { try { Time time = Time.valueOf(result); return new Timestamp(time.getTime()).toString(); } catch (IllegalArgumentException ex) { } } break; } } return result; }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the SQL type name for the given {@link Types} constant. *//*from w w w .ja v a2 s.co m*/ public static String getJDBCName(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.CHAR: return "char"; case Types.CLOB: return "clob"; 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 "unknown(" + type + ")"; } }
From source file:com.trackplus.ddl.GenericStringValueConverter.java
protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType) throws SQLException, DDLException { String value = resultSet.getString(columnIdx); if (value != null) { switch (jdbcType) { case Types.NUMERIC: case Types.DECIMAL: break; case Types.BIT: case Types.BOOLEAN: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: { break; }/*from ww w.ja v a 2s . c o m*/ case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.BINARY: case Types.VARBINARY: case Types.TIME: case Types.CLOB: case Types.ARRAY: case Types.REF: { value = "'" + value.replaceAll("'", "''") + "'"; break; } case Types.DATE: case Types.TIMESTAMP: { Date d = resultSet.getDate(columnIdx); Calendar cal = Calendar.getInstance(); cal.setTime(d); int year = cal.get(Calendar.YEAR); if (year < 1900) { throw new DDLException("Invalid date:" + d); } else { value = "'" + value + "'"; } break; } case Types.BLOB: case Types.LONGVARBINARY: { Blob blobValue = resultSet.getBlob(columnIdx); String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length()))); value = "'" + str + "'"; break; } default: break; } } return value; }
From source file:com.squid.core.jdbc.vendor.sqlserver.SQLServerJDBCDataFormatter.java
@Override public Object unboxJDBCObject(final Object column, final int colType) throws SQLException { switch (colType) { case 1:// CHAR if (column != null) { return StringUtils.stripEnd((String) column, " "); } else {/*from ww w . j a va2 s.c om*/ return null; } case -9: //NVARCHAR case -15: //NCHAR if (column == null) { return null; } else { return column.toString(); } case Types.BIT: if (column instanceof Boolean && column != null) { if (((Boolean) column).booleanValue() == true) { return 1; } else { return 0; } } if (column != null) { return column.toString(); } else { return null; } } return column; }
From source file:com.draagon.meta.manager.db.driver.MSSQLDriver.java
/** * Creates a table in the database//from w w w. ja v a 2 s.c om */ @Override public void createTable(Connection c, TableDef table) throws SQLException { String query = "CREATE TABLE [" + table + "] (\n"; boolean multi = (table.getPrimaryKeys().size() > 1); boolean hasIdentity = false; // Create the individual table fields int found = 0; for (ColumnDef col : table.getColumns()) { String name = col.getName(); if (name == null || name.length() == 0) { throw new IllegalArgumentException("No name defined for column [" + col + "]"); } if (found > 0) query += ",\n"; found++; String flags = ""; if (col.isPrimaryKey() && !multi) flags = "PRIMARY KEY "; else if (col.isUnique()) flags = "UNIQUE "; //else if (getManager().isIndex(mf)) flags = "NONCLUSTERED "; switch (col.getSQLType()) { case Types.BOOLEAN: case Types.BIT: query += "[" + name + "] [bit] " + flags; break; case Types.TINYINT: query += "[" + name + "] [tinyint] " + flags; break; case Types.SMALLINT: query += "[" + name + "] [smallint] " + flags; break; case Types.INTEGER: query += "[" + name + "] [int] " + flags; break; case Types.BIGINT: query += "[" + name + "] [bigint] " + flags; break; case Types.FLOAT: query += "[" + name + "] [float] " + flags; break; case Types.DOUBLE: query += "[" + name + "] [decimal](19,4) " + flags; break; case Types.TIMESTAMP: query += "[" + name + "] [datetime] " + flags; break; case Types.VARCHAR: query += "[" + name + "] [varchar](" + col.getLength() + ") " + flags; break; default: throw new IllegalArgumentException("Table [" + table + "] with Column [" + col + "] is of SQL type (" + col.getSQLType() + ") which is not support by this database"); } // Create the identity columns if (col.isAutoIncrementor()) { if (hasIdentity) throw new MetaException( "Table [" + table + "] cannot have multiple identity (auto id) columns!"); query += "NOT NULL IDENTITY( " + col.getSequence().getStart() + ", " + col.getSequence().getIncrement() + " ) "; hasIdentity = true; } } query += "\n)"; // This means there were no columns defined for the table if (found == 0) return; if (log.isDebugEnabled()) { log.debug("Creating table [" + table + "]: " + query); } //ystem.out.println( ">>>> Creating table [" + table + "]: " + query); Statement s = c.createStatement(); try { s.execute(query); } finally { s.close(); } }
From source file:org.apache.ddlutils.io.converters.NumberConverter.java
/** * {@inheritDoc}/* w ww . ja v a2 s. c o m*/ */ public String convertToString(Object obj, int sqlTypeCode) throws ConversionException { if (obj == null) { return null; } else if (sqlTypeCode == Types.BIT) { return ((Boolean) obj).booleanValue() ? "1" : "0"; } else { return obj.toString(); } }
From source file:org.talend.dataquality.record.linkage.ui.composite.table.SortComparator.java
public static ISortComparator getSortComparator(int javaDataType) throws ParseException { switch (javaDataType) { case Types.DATE: case Types.TIME: return new SortComparator() { @Override// w w w .j ava2 s.com public int compareNotNull(Object value1, Object value2) throws ParseException { return java.sql.Date.valueOf(value1.toString()) .compareTo(java.sql.Date.valueOf(value2.toString())); } }; case Types.TIMESTAMP: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Timestamp.valueOf(value1.toString()).compareTo(Timestamp.valueOf(value2.toString())); } }; case Types.DOUBLE: case Types.REAL: case Types.FLOAT: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Double.valueOf(value1.toString()).compareTo(Double.valueOf(value2.toString())); } }; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.NUMERIC: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Integer.valueOf(value1.toString()).compareTo(Integer.valueOf(value2.toString())); } }; case Types.BIGINT: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Long.valueOf(value1.toString()).compareTo(Long.valueOf(value2.toString())); } }; case Types.DECIMAL: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { if (value1 instanceof BigDecimal) { return ((BigDecimal) value1).compareTo((BigDecimal) value2); } BigDecimal b1 = new BigDecimal(value1.toString()); BigDecimal b2 = new BigDecimal(value2.toString()); return b1.compareTo(b2); } }; case Types.BOOLEAN: case Types.BIT: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Boolean.valueOf(value1.toString()).compareTo(Boolean.valueOf(value2.toString())); } }; default:// String return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return value1.toString().compareTo(value2.toString()); } }; } }