Java Code Examples for java.sql.Types#BIT
The following examples show how to use
java.sql.Types#BIT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberConverter.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ 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(); } }
Example 2
Source File: SQLServer.java From GeoTriples with Apache License 2.0 | 6 votes |
@Override public DataType getDataType(int jdbcType, String name, int size) { // MS SQLServer 2008 driver returns DATE as VARCHAR type if (name.equals("DATE")) { return new SQLDate(name); } // On SQL Server, BIT is a single-bit numeric type if (jdbcType == Types.BIT) { return new SQLServerCompatibilityBitDataType(); } // Doesn't support DISTINCT over LOB types if (jdbcType == Types.CLOB || "NCLOB".equals(name)) { return new SQLCharacterStringVarying(name, false); } if (jdbcType == Types.BLOB) { return new SQLBinary(name, false); } return super.getDataType(jdbcType, name, size); }
Example 3
Source File: BinaryRelationalOperatorNode.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Return 50% if this is a comparison with a boolean column, a negative * selectivity otherwise. */ protected double booleanSelectivity(Optimizable optTable) throws StandardException { TypeId typeId = null; double retval = -1.0d; int columnSide; columnSide = columnOnOneSide(optTable); if (columnSide == LEFT) typeId = leftOperand.getTypeId(); else if (columnSide == RIGHT) typeId = rightOperand.getTypeId(); if (typeId != null && (typeId.getJDBCTypeId() == Types.BIT || typeId.getJDBCTypeId() == Types.BOOLEAN)) retval = 0.5d; return retval; }
Example 4
Source File: BinaryRelationalOperatorNode.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * Return 50% if this is a comparison with a boolean column, a negative * selectivity otherwise. */ protected double booleanSelectivity(Optimizable optTable) throws StandardException{ TypeId typeId=null; double retval=-1.0d; int columnSide; columnSide=columnOnOneSide(optTable); if(columnSide==LEFT) typeId=leftOperand.getTypeId(); else if(columnSide==RIGHT) typeId=rightOperand.getTypeId(); if(typeId!=null && (typeId.getJDBCTypeId()==Types.BIT || typeId.getJDBCTypeId()==Types.BOOLEAN)) retval=0.5d; return retval; }
Example 5
Source File: DatabaseUtil.java From nextreports-server with Apache License 2.0 | 6 votes |
public static String getJavaType(int jdbcType) { switch (jdbcType) { case Types.BIT: return Boolean.class.getName(); case Types.TINYINT: return Byte.class.getName(); case Types.SMALLINT: return Short.class.getName(); case Types.CHAR: return String.class.getName(); case Types.VARCHAR: return String.class.getName(); case Types.DATE: return Date.class.getName(); case Types.TIME: return Time.class.getName(); case Types.TIMESTAMP: return Timestamp.class.getName(); case Types.DOUBLE: return Double.class.getName(); case Types.FLOAT: return Float.class.getName(); case Types.INTEGER: return Integer.class.getName(); case Types.BIGINT: return BigInteger.class.getName(); case Types.NUMERIC: return BigDecimal.class.getName(); case Types.DECIMAL: return BigDecimal.class.getName(); case Types.BINARY: return byte[].class.getName(); case Types.VARBINARY: return byte[].class.getName(); case Types.OTHER: return Object.class.getName(); default: return String.class.getName(); } }
Example 6
Source File: ResultSet.java From birt with Eclipse Public License 1.0 | 5 votes |
public int getInt( int index ) throws OdaException { assertNotNull( rs ); try { /* redirect the call to JDBC ResultSet.getInt(int) */ return rs.getInt( index ); } catch ( SQLException e ) { // check if it's postgresql boolean dataType try { if ( rs.getMetaData( ).getColumnType( index ) == Types.BIT ) { if ( rs.getString( index ).equals( "t" ) ) //$NON-NLS-1$ return 1; else if ( rs.getString( index ).equals( "f" ) ) //$NON-NLS-1$ return 0; } logger.log( Level.WARNING, e.getLocalizedMessage( ) ); return 0; } catch ( SQLException ex ) { logger.log( Level.WARNING, e.getLocalizedMessage( ) ); return 0; } } }
Example 7
Source File: JDBCAdapter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public String dbRepresentation(int column, Object value) { int type; if (value == null) { return "null"; } try { type = metaData.getColumnType(column + 1); } catch (SQLException e) { return value.toString(); } switch (type) { case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: return value.toString(); case Types.BIT: return ((Boolean) value).booleanValue() ? "1" : "0"; case Types.DATE: return value.toString(); // This will need some conversion. default: return "\"" + value.toString() + "\""; } }
Example 8
Source File: JDBCAdapter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public Class<?> getColumnClass(int column) { int type; try { type = metaData.getColumnType(column + 1); } catch (SQLException e) { return super.getColumnClass(column); } switch (type) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return String.class; case Types.BIT: return Boolean.class; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return Integer.class; case Types.BIGINT: return Long.class; case Types.FLOAT: case Types.DOUBLE: return Double.class; case Types.DATE: return java.sql.Date.class; default: return Object.class; } }
Example 9
Source File: SqlCommandExtend.java From fixflow with Apache License 2.0 | 5 votes |
/** * 得到数据类型的整型值 * * @param typeName * 类型名称 * @return 数据类型的整型值 */ private int getDataType(String typeName) { if (typeName.equals("varchar")) return Types.VARCHAR; if (typeName.equals("int")) return Types.INTEGER; if (typeName.equals("bit")) return Types.BIT; if (typeName.equals("float")) return Types.FLOAT; return 0; }
Example 10
Source File: JdbcUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Check whether the given SQL type is numeric. * @param sqlType the SQL type to be checked * @return whether the type is numeric */ public static boolean isNumeric(int sqlType) { return Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType || Types.DOUBLE == sqlType || Types.FLOAT == sqlType || Types.INTEGER == sqlType || Types.NUMERIC == sqlType || Types.REAL == sqlType || Types.SMALLINT == sqlType || Types.TINYINT == sqlType; }
Example 11
Source File: PostgreSpecific.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
@Override public char sqlType2jetel(int sqlType) { switch (sqlType) { case Types.BIT: return DataFieldMetadata.BOOLEAN_FIELD; default: return super.sqlType2jetel(sqlType); } }
Example 12
Source File: ResultSetToKVStoreSerializer.java From AILibs with GNU Affero General Public License v3.0 | 4 votes |
public IKVStore serializeRow(final ResultSet values, final String[] columnNames, final int[] columnTypes) throws SQLException, ResultSetSerializerException { KVStore store = new KVStore(); for (int i = 0; i < columnNames.length; i++) { String fieldName = columnNames[i]; switch (columnTypes[i]) { case Types.INTEGER: store.put(fieldName, values.getInt(i + 1)); break; case Types.BIGINT: store.put(fieldName, values.getLong(i + 1)); break; case Types.DECIMAL: case Types.NUMERIC: store.put(fieldName, values.getBigDecimal(i + 1)); break; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: store.put(fieldName, values.getDouble(i + 1)); break; case Types.NVARCHAR: case Types.VARCHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: store.put(fieldName, values.getString(i + 1)); break; case Types.BOOLEAN: case Types.BIT: store.put(fieldName, values.getBoolean(i + 1)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: store.put(fieldName, values.getByte(i + 1)); break; case Types.TINYINT: case Types.SMALLINT: store.put(fieldName, values.getShort(i + 1)); break; case Types.DATE: store.put(fieldName, values.getDate(i + 1)); break; case Types.TIMESTAMP: store.put(fieldName, values.getTime(i + 1)); break; case Types.BLOB: store.put(fieldName, values.getBlob(i)); break; case Types.CLOB: store.put(fieldName, values.getClob(i)); break; case Types.ARRAY: throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type ARRAY"); case Types.STRUCT: throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type STRUCT"); case Types.DISTINCT: throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type DISTINCT"); case Types.REF: throw new ResultSetSerializerException("ResultSetSerializer not yet implemented for SQL type REF"); case Types.JAVA_OBJECT: default: store.put(fieldName, values.getObject(i + 1)); break; } if (values.wasNull()) { store.put(fieldName, null); } } return store; }
Example 13
Source File: SqlTypeSide.java From CQL with GNU Affero General Public License v3.0 | 4 votes |
public static int getSqlType(String s) { switch (s.toLowerCase()) { case "varbinary": return Types.VARBINARY; case "longvarbinary": return Types.LONGVARBINARY; case "binary": return Types.BINARY; case "date": return Types.DATE; case "time": return Types.TIME; case "timestamp": return Types.TIMESTAMP; case "bigint": return Types.BIGINT; case "boolean": return Types.BOOLEAN; case "char": return Types.CHAR; case "double": return Types.DOUBLE; case "doubleprecision": return Types.DOUBLE; case "numeric": return Types.NUMERIC; case "decimal": return Types.DECIMAL; case "real": return Types.REAL; case "float": return Types.FLOAT; case "integer": return Types.INTEGER; case "tinyint": return Types.TINYINT; case "bit": return Types.BIT; case "smallint": return Types.SMALLINT; case "nvarchar": return Types.NVARCHAR; case "longvarchar": return Types.LONGVARCHAR; case "text": return Types.VARCHAR; case "varchar": return Types.VARCHAR; case "string": return Types.VARCHAR; case "blob": return Types.BLOB; case "other": return Types.OTHER; case "clob": return Types.CLOB; // case "long": return Types.Lo } // Types. throw new RuntimeException("Unknown sql type: " + s); }
Example 14
Source File: PrestoPreparedStatement.java From presto with Apache License 2.0 | 4 votes |
private static String typedNull(int targetSqlType) throws SQLException { switch (targetSqlType) { case Types.BOOLEAN: case Types.BIT: return typedNull("BOOLEAN"); case Types.TINYINT: return typedNull("TINYINT"); case Types.SMALLINT: return typedNull("SMALLINT"); case Types.INTEGER: return typedNull("INTEGER"); case Types.BIGINT: return typedNull("BIGINT"); case Types.FLOAT: case Types.REAL: return typedNull("REAL"); case Types.DOUBLE: return typedNull("DOUBLE"); case Types.DECIMAL: case Types.NUMERIC: return typedNull("DECIMAL"); case Types.CHAR: case Types.NCHAR: return typedNull("CHAR"); case Types.VARCHAR: case Types.NVARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.CLOB: case Types.NCLOB: return typedNull("VARCHAR"); case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: return typedNull("VARBINARY"); case Types.DATE: return typedNull("DATE"); case Types.TIME: return typedNull("TIME"); case Types.TIMESTAMP: return typedNull("TIMESTAMP"); // TODO Types.TIME_WITH_TIMEZONE // TODO Types.TIMESTAMP_WITH_TIMEZONE case Types.NULL: return "NULL"; } throw new SQLException("Unsupported target SQL type: " + targetSqlType); }
Example 15
Source File: ResultSetRecordSet.java From nifi with Apache License 2.0 | 4 votes |
private static RecordFieldType getFieldType(final int sqlType, final String valueClassName) { switch (sqlType) { case Types.BIGINT: case Types.ROWID: return RecordFieldType.LONG; case Types.BIT: case Types.BOOLEAN: return RecordFieldType.BOOLEAN; case Types.CHAR: return RecordFieldType.CHAR; case Types.DATE: return RecordFieldType.DATE; case Types.NUMERIC: case Types.DECIMAL: return RecordFieldType.DECIMAL; case Types.DOUBLE: case Types.REAL: return RecordFieldType.DOUBLE; case Types.FLOAT: return RecordFieldType.FLOAT; case Types.INTEGER: return RecordFieldType.INT; case Types.SMALLINT: return RecordFieldType.SHORT; case Types.TINYINT: return RecordFieldType.BYTE; case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NULL: case Types.NVARCHAR: case Types.VARCHAR: return RecordFieldType.STRING; case Types.OTHER: case Types.JAVA_OBJECT: if (STRING_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.STRING; } if (INT_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.INT; } if (LONG_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.LONG; } if (DATE_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.DATE; } if (FLOAT_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.FLOAT; } if (DOUBLE_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.DOUBLE; } if (BIGDECIMAL_CLASS_NAME.equals(valueClassName)) { return RecordFieldType.DECIMAL; } return RecordFieldType.RECORD; case Types.TIME: case Types.TIME_WITH_TIMEZONE: return RecordFieldType.TIME; case Types.TIMESTAMP: case Types.TIMESTAMP_WITH_TIMEZONE: case -101: // Oracle's TIMESTAMP WITH TIME ZONE case -102: // Oracle's TIMESTAMP WITH LOCAL TIME ZONE return RecordFieldType.TIMESTAMP; } return RecordFieldType.STRING; }
Example 16
Source File: TypeConverter.java From jpa-entity-generator with MIT License | 4 votes |
public static String toJavaType(int typeCode) { switch (typeCode) { case Types.ARRAY: return "Array"; case Types.BIGINT: return "Long"; // case Types.BINARY: case Types.BIT: // return "Boolean"; return "boolean"; case Types.BLOB: return "Blob"; case Types.BOOLEAN: return "Boolean"; case Types.CHAR: return "String"; case Types.CLOB: return "Clob"; // case Types.DATALINK: case Types.DATE: return "Date"; case Types.DECIMAL: return "java.math.BigDecimal"; // case Types.DISTINCT: case Types.DOUBLE: return "Double"; case Types.FLOAT: return "Float"; case Types.INTEGER: return "Integer"; // case Types.JAVA_OBJECT: // case Types.LONGNVARCHAR: // case Types.LONGVARBINARY: case Types.LONGVARCHAR: return "String"; // case Types.NCHAR: // case Types.NCLOB: // case Types.NULL: case Types.NUMERIC: return "java.math.BigDecimal"; // case Types.NVARCHAR: // case Types.OTHER: case Types.REAL: return "Float"; case Types.REF: return "Ref"; // case Types.REF_CURSOR: // case Types.ROWID: case Types.SMALLINT: return "Short"; // case Types.SQLXML: case Types.STRUCT: return "Struct"; case Types.TIME: return "Time"; case Types.TIME_WITH_TIMEZONE: return "Time"; case Types.TIMESTAMP: return "Timestamp"; case Types.TIMESTAMP_WITH_TIMEZONE: return "Timestamp"; case Types.TINYINT: return "Byte"; // case Types.VARBINARY: case Types.VARCHAR: return "String"; default: return "String"; } }
Example 17
Source File: JDBCServiceMethod.java From diirt with MIT License | 4 votes |
/** * Maps a result set to a VTable. */ static VTable resultSetToVTable(ResultSet resultSet) throws SQLException { ResultSetMetaData metaData = resultSet.getMetaData(); int nColumns = metaData.getColumnCount(); List<Class<?>> types = new ArrayList<>(nColumns); List<Object> data = new ArrayList<>(nColumns); List<String> names = new ArrayList<>(nColumns); for (int j = 1; j <= nColumns; j++) { names.add(metaData.getColumnName(j)); switch (metaData.getColumnType(j)) { case Types.DOUBLE: case Types.FLOAT: // XXX: NUMERIC should be BigInteger case Types.NUMERIC: // XXX: Integers should be Long/Int case Types.INTEGER: case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: types.add(double.class); data.add(new CircularBufferDouble(Integer.MAX_VALUE)); break; case Types.LONGNVARCHAR: case Types.CHAR: case Types.VARCHAR: // XXX: should be a booloean case Types.BOOLEAN: case Types.BIT: types.add(String.class); data.add(new ArrayList<>()); break; case Types.TIMESTAMP: types.add(Instant.class); data.add(new ArrayList<>()); break; default: if ("java.lang.String".equals(metaData.getColumnClassName(j))) { types.add(String.class); data.add(new ArrayList<>()); } else { throw new IllegalArgumentException("Unsupported type " + metaData.getColumnTypeName(j)); } } } while (resultSet.next()) { for (int i = 0; i < nColumns; i++) { Class<?> type = types.get(i); if (type.equals(String.class)) { @SuppressWarnings("unchecked") List<String> strings = (List<String>) data.get(i); strings.add(resultSet.getString(i+1)); } else if (type.equals(Instant.class)) { @SuppressWarnings("unchecked") List<Instant> timestamps = (List<Instant>) data.get(i); java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp(i+1); if (sqlTimestamp == null) { timestamps.add(null); } else { timestamps.add((new Date(sqlTimestamp.getTime())).toInstant()); } } else if (type.equals(double.class)) { ((CircularBufferDouble) data.get(i)).addDouble(resultSet.getDouble(i+1)); } } } return ValueFactory.newVTable(types, names, data); }
Example 18
Source File: MariaDbResultSetMetaData.java From mariadb-connector-j with GNU Lesser General Public License v2.1 | 4 votes |
/** * Retrieves the designated column's SQL type. * * @param column the first column is 1, the second is 2, ... * @return SQL type from java.sql.Types * @throws SQLException if a database access error occurs * @see Types */ public int getColumnType(final int column) throws SQLException { ColumnDefinition ci = getColumnInformation(column); switch (ci.getColumnType()) { case BIT: if (ci.getLength() == 1) { return Types.BIT; } return Types.VARBINARY; case TINYINT: if (ci.getLength() == 1 && options.tinyInt1isBit) { return Types.BIT; } return Types.TINYINT; case YEAR: if (options.yearIsDateType) { return Types.DATE; } return Types.SMALLINT; case BLOB: if (ci.getLength() < 0 || ci.getLength() > 16777215) { return Types.LONGVARBINARY; } return Types.VARBINARY; case VARCHAR: case VARSTRING: if (ci.isBinary()) { return Types.VARBINARY; } if (ci.getLength() < 0) { return Types.LONGVARCHAR; } return Types.VARCHAR; case STRING: if (ci.isBinary()) { return Types.BINARY; } return Types.CHAR; default: return ci.getColumnType().getSqlType(); } }
Example 19
Source File: GfxdCBArgForSynchPrms.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
static final DataValueDescriptor getNullDVD(int sqlType) { switch (sqlType) { case Types.BINARY: return new SQLBit(); case Types.BIT: case Types.BOOLEAN: return new SQLBoolean(); case Types.CHAR: return new SQLChar(); case Types.DATE: return new SQLDate(); case Types.DOUBLE: return new SQLDouble(); case Types.INTEGER: return new SQLInteger(); case Types.BIGINT: return new SQLLongint(); case Types.DECIMAL: case Types.NUMERIC: return new SQLDecimal(); case Types.FLOAT: case Types.REAL: return new SQLReal(); case Types.SMALLINT: return new SQLSmallint(); case Types.TIME: return new SQLTime(); case Types.TIMESTAMP: return new SQLTimestamp(); case Types.TINYINT: return new SQLTinyint(); case Types.VARCHAR: return new SQLVarchar(); case Types.LONGVARCHAR: return new SQLLongvarchar(); case Types.VARBINARY: return new SQLVarbit(); case Types.LONGVARBINARY: return new SQLLongVarbit(); case Types.REF: return new SQLRef(); case BLOB: final SQLBlob blob = new SQLBlob(); blob.setWrapBytesForSQLBlob(true); return blob; case CLOB: return new SQLClob(); case JAVA_OBJECT: return new UserType(); case SQLXML: return new XML(); case JSON: return new JSON(); default: throw GemFireXDRuntimeException.newRuntimeException( "unexpected SQL type=" + sqlType, null); } }
Example 20
Source File: TestAgainstLiveDatabaseBase.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Returns a copy of the given model adjusted for type changes because of the native type mappings * which when read back from the database will map to different types. * * @param sourceModel The source model * @return The adjusted model */ protected Database adjustModel(Database sourceModel) { Database model = new CloneHelper().clone(sourceModel); for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++) { Table table = model.getTable(tableIdx); for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++) { Column column = table.getColumn(columnIdx); int origType = column.getTypeCode(); int targetType = getPlatformInfo().getTargetJdbcType(origType); // we adjust the column types if the native type would back-map to a // different jdbc type if (targetType != origType) { column.setTypeCode(targetType); // we should also adapt the default value if (column.getDefaultValue() != null) { DefaultValueHelper helper = getPlatform().getSqlBuilder().getDefaultValueHelper(); column.setDefaultValue(helper.convert(column.getDefaultValue(), origType, targetType)); } } // we also promote the default size if the column has no size // spec of its own if ((column.getSize() == null) && getPlatformInfo().hasSize(targetType)) { Integer defaultSize = getPlatformInfo().getDefaultSize(targetType); if (defaultSize != null) { column.setSize(defaultSize.toString()); } } // finally the platform might return a synthetic default value if the column // is a primary key column if (getPlatformInfo().isSyntheticDefaultValueForRequiredReturned() && (column.getDefaultValue() == null) && column.isRequired() && !column.isAutoIncrement()) { switch (column.getTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: column.setDefaultValue("0"); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: column.setDefaultValue("0.0"); break; case Types.BIT: column.setDefaultValue("false"); break; default: column.setDefaultValue(""); break; } } if (column.isPrimaryKey() && getPlatformInfo().isPrimaryKeyColumnAutomaticallyRequired()) { column.setRequired(true); } if (column.isAutoIncrement() && getPlatformInfo().isIdentityColumnAutomaticallyRequired()) { column.setRequired(true); } } // we also add the default names to foreign keys that are initially unnamed for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++) { ForeignKey fk = table.getForeignKey(fkIdx); if (fk.getName() == null) { fk.setName(getPlatform().getSqlBuilder().getForeignKeyName(table, fk)); } } } return model; }