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.jumpmind.db.platform.AbstractDatabasePlatform.java
public String[] getStringValues(BinaryEncoding encoding, Column[] metaData, Row row, boolean useVariableDates, boolean indexByPosition) { String[] values = new String[metaData.length]; Set<String> keys = row.keySet(); int i = 0;/*w ww. j a v a 2s. c o m*/ for (String key : keys) { Column column = metaData[i]; String name = indexByPosition ? key : column.getName(); int type = column.getJdbcTypeCode(); if (row.get(name) != null) { if (type == Types.BOOLEAN || type == Types.BIT) { values[i] = row.getBoolean(name) ? "1" : "0"; } else if (column.isOfNumericType()) { values[i] = row.getString(name); } else if (!column.isTimestampWithTimezone() && (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME)) { values[i] = getDateTimeStringValue(name, type, row, useVariableDates); } else if (column.isOfBinaryType()) { byte[] bytes = row.getBytes(name); if (encoding == BinaryEncoding.NONE) { values[i] = row.getString(name); } else if (encoding == BinaryEncoding.BASE64) { values[i] = new String(Base64.encodeBase64(bytes)); } else if (encoding == BinaryEncoding.HEX) { values[i] = new String(Hex.encodeHex(bytes)); } } else { values[i] = row.getString(name); } } i++; } return values; }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java
public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize, int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction, boolean timestampToString) throws SQLException, IOException, StageException { Field field;/*ww w . j ava 2 s. c o m*/ if (userSpecifiedType != DataType.USE_COLUMN_TYPE) { // If user specifies the data type, overwrite the column type returned by database. field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex)); } else { // All types as of JDBC 2.0 are here: // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY // Good source of recommended mappings is here: // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html switch (md.getColumnType(columnIndex)) { case Types.BIGINT: field = Field.create(Field.Type.LONG, rs.getObject(columnIndex)); break; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex)); break; case Types.BIT: case Types.BOOLEAN: field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex)); break; case Types.CHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.VARCHAR: field = Field.create(Field.Type.STRING, rs.getObject(columnIndex)); break; case Types.CLOB: case Types.NCLOB: field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize)); break; case Types.BLOB: field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize)); break; case Types.DATE: field = Field.create(Field.Type.DATE, rs.getDate(columnIndex)); break; case Types.DECIMAL: case Types.NUMERIC: field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex)); field.setAttribute(HeaderAttributeConstants.ATTR_SCALE, String.valueOf(rs.getMetaData().getScale(columnIndex))); field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION, String.valueOf(rs.getMetaData().getPrecision(columnIndex))); break; case Types.DOUBLE: field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex)); break; case Types.FLOAT: case Types.REAL: field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex)); break; case Types.INTEGER: field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex)); break; case Types.ROWID: field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString()); break; case Types.SMALLINT: case Types.TINYINT: field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex)); break; case Types.TIME: field = Field.create(Field.Type.TIME, rs.getObject(columnIndex)); break; case Types.TIMESTAMP: final Timestamp timestamp = rs.getTimestamp(columnIndex); if (timestampToString) { field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString()); } else { field = Field.create(Field.Type.DATETIME, timestamp); if (timestamp != null) { final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT; if (actualNanos > 0) { field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos)); } } } break; // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc. case Types.TIME_WITH_TIMEZONE: OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class); field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant())); break; case Types.TIMESTAMP_WITH_TIMEZONE: OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class); field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime()); break; //case Types.REF_CURSOR: // JDK8 only case Types.SQLXML: case Types.STRUCT: case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: default: if (unknownTypeAction == null) { return null; } switch (unknownTypeAction) { case STOP_PIPELINE: throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex), md.getColumnLabel(columnIndex)); case CONVERT_TO_STRING: Object value = rs.getObject(columnIndex); if (value != null) { field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString()); } else { field = Field.create(Field.Type.STRING, null); } break; default: throw new IllegalStateException("Unknown action: " + unknownTypeAction); } } } return field; }
From source file:org.executequery.gui.resultset.ResultSetTableModel.java
public Class<?> getColumnClass(int column) { if (tableData.isEmpty()) { return String.class; }//from w ww .j a va2 s. co m RecordDataItem recordDataItem = tableData.get(0).get(column); if (recordDataItem.isValueNull()) { return String.class; } int columnType = recordDataItem.getDataType(); switch (columnType) { case Types.TINYINT: return Byte.class; case Types.BIGINT: return Long.class; case Types.SMALLINT: return Short.class; case Types.BIT: case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: case Types.BOOLEAN: // don't display the checkbox return String.class; case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class; case Types.INTEGER: return Integer.class; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return java.util.Date.class; case Types.REAL: return Float.class; case Types.FLOAT: case Types.DOUBLE: return Double.class; default: return Object.class; } }
From source file:org.apache.openjpa.jdbc.schema.Column.java
/** * Return true if this column is compatible with the given JDBC type * from {@link Types} and size.// w w w . j av a 2s . c o m */ public boolean isCompatible(int type, String typeName, int size, int decimals) { if (type == Types.OTHER || getType() == Types.OTHER) return true; // note that the given size is currently ignored, but may be useful // to dynamically-populating subclasses switch (getType()) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: switch (type) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: return true; default: return false; } case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.OTHER: switch (type) { case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.OTHER: return true; default: return false; } case Types.CLOB: case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: switch (type) { case Types.CLOB: case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return true; default: return false; } case Types.DATE: case Types.TIME: case Types.TIMESTAMP: switch (type) { case Types.LONGVARCHAR: case Types.CLOB: case Types.VARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return true; default: return false; } case 2007: // Oracle-defined opaque type code for XMLType switch (type) { case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CLOB: case Types.BLOB: return true; default: return false; } default: return type == getType(); } }
From source file:org.apache.cocoon.util.JDBCTypeConversions.java
/** * Set the Statement column so that the results are mapped correctly. * * @param statement the prepared statement * @param position the position of the column * @param value the value of the column/*from w w w . j a v a 2 s . c om*/ */ public static void setColumn(PreparedStatement statement, int position, Object value, Integer typeObject) throws Exception { if (value instanceof String) { value = ((String) value).trim(); } if (typeObject == null) { throw new SQLException("Can't set column because the type is unrecognized"); } if (value == null) { /** If the value is null, set the column value null and return **/ statement.setNull(position, typeObject.intValue()); return; } if ("".equals(value)) { switch (typeObject.intValue()) { case Types.CHAR: case Types.CLOB: case Types.VARCHAR: /** If the value is an empty string and the column is a string type, we can continue **/ break; default: /** If the value is an empty string and the column is something else, we treat it as a null value **/ statement.setNull(position, typeObject.intValue()); return; } } File file = null; int length = -1; InputStream asciiStream = null; //System.out.println("========================================================================"); //System.out.println("JDBCTypeConversions: setting type "+typeObject.intValue()); switch (typeObject.intValue()) { case Types.CLOB: //System.out.println("CLOB"); Clob clob = null; if (value instanceof Clob) { clob = (Clob) value; } else if (value instanceof File) { File asciiFile = (File) value; asciiStream = new BufferedInputStream(new FileInputStream(asciiFile)); length = (int) asciiFile.length(); clob = new ClobHelper(asciiStream, length); } else if (value instanceof Part) { Part anyFile = (Part) value; asciiStream = new BufferedInputStream(anyFile.getInputStream()); length = anyFile.getSize(); clob = new ClobHelper(asciiStream, length); } else if (value instanceof JDBCxlobHelper) { asciiStream = ((JDBCxlobHelper) value).inputStream; length = ((JDBCxlobHelper) value).length; clob = new ClobHelper(asciiStream, length); } else if (value instanceof Source) { asciiStream = ((Source) value).getInputStream(); length = (int) ((Source) value).getContentLength(); clob = new ClobHelper(asciiStream, length); } else { String asciiText = value.toString(); asciiStream = new ByteArrayInputStream(asciiText.getBytes()); length = asciiText.length(); clob = new ClobHelper(asciiStream, length); } statement.setClob(position, clob); break; case Types.CHAR: // simple large object, e.g. Informix's TEXT //System.out.println("CHAR"); if (value instanceof File) { File asciiFile = (File) value; asciiStream = new BufferedInputStream(new FileInputStream(asciiFile)); length = (int) asciiFile.length(); } else if (value instanceof JDBCxlobHelper) { asciiStream = ((JDBCxlobHelper) value).inputStream; length = ((JDBCxlobHelper) value).length; } else if (value instanceof Source) { asciiStream = ((Source) value).getInputStream(); length = (int) ((Source) value).getContentLength(); } else if (value instanceof Part) { Part anyFile = (Part) value; asciiStream = new BufferedInputStream(anyFile.getInputStream()); length = anyFile.getSize(); clob = new ClobHelper(asciiStream, length); } else { String asciiText = value.toString(); asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes())); length = asciiText.length(); } statement.setAsciiStream(position, asciiStream, length); break; case Types.BIGINT: //System.out.println("BIGINT"); BigDecimal bd = null; if (value instanceof BigDecimal) { bd = (BigDecimal) value; } else if (value instanceof Number) { bd = BigDecimal.valueOf(((Number) value).longValue()); } else { bd = new BigDecimal(value.toString()); } statement.setBigDecimal(position, bd); break; case Types.TINYINT: //System.out.println("TINYINT"); Byte b = null; if (value instanceof Byte) { b = (Byte) value; } else if (value instanceof Number) { b = new Byte(((Number) value).byteValue()); } else { b = new Byte(value.toString()); } statement.setByte(position, b.byteValue()); break; case Types.DATE: //System.out.println("DATE"); Date d = null; if (value instanceof Date) { d = (Date) value; } else if (value instanceof java.util.Date) { d = new Date(((java.util.Date) value).getTime()); } else if (value instanceof Calendar) { d = new Date(((Calendar) value).getTime().getTime()); } else { d = Date.valueOf(value.toString()); } statement.setDate(position, d); break; case Types.DOUBLE: //System.out.println("DOUBLE"); double db; if (value instanceof Number) { db = (((Number) value).doubleValue()); } else { db = Double.parseDouble(value.toString()); } statement.setDouble(position, db); break; case Types.FLOAT: //System.out.println("FLOAT"); float f; if (value instanceof Number) { f = (((Number) value).floatValue()); } else { f = Float.parseFloat(value.toString()); } statement.setFloat(position, f); break; case Types.NUMERIC: //System.out.println("NUMERIC"); long l; if (value instanceof Number) { l = (((Number) value).longValue()); } else { l = Long.parseLong(value.toString()); } statement.setLong(position, l); break; case Types.SMALLINT: //System.out.println("SMALLINT"); Short s = null; if (value instanceof Short) { s = (Short) value; } else if (value instanceof Number) { s = new Short(((Number) value).shortValue()); } else { s = new Short(value.toString()); } statement.setShort(position, s.shortValue()); break; case Types.TIME: //System.out.println("TIME"); Time t = null; if (value instanceof Time) { t = (Time) value; } else if (value instanceof java.util.Date) { t = new Time(((java.util.Date) value).getTime()); } else { t = Time.valueOf(value.toString()); } statement.setTime(position, t); break; case Types.TIMESTAMP: //System.out.println("TIMESTAMP"); Timestamp ts = null; if (value instanceof Time) { ts = (Timestamp) value; } else if (value instanceof java.util.Date) { ts = new Timestamp(((java.util.Date) value).getTime()); } else { ts = Timestamp.valueOf(value.toString()); } statement.setTimestamp(position, ts); break; case Types.ARRAY: //System.out.println("ARRAY"); statement.setArray(position, (Array) value); // no way to convert string to array break; case Types.STRUCT: //System.out.println("STRUCT"); case Types.OTHER: //System.out.println("OTHER"); statement.setObject(position, value); break; case Types.LONGVARBINARY: //System.out.println("LONGVARBINARY"); statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime())); break; case Types.VARCHAR: //System.out.println("VARCHAR"); statement.setString(position, value.toString()); break; case Types.BLOB: //System.out.println("BLOB"); if (value instanceof JDBCxlobHelper) { statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream, ((JDBCxlobHelper) value).length); } else if (value instanceof Source) { statement.setBinaryStream(position, ((Source) value).getInputStream(), (int) ((Source) value).getContentLength()); } else { Blob blob = null; if (value instanceof Blob) { blob = (Blob) value; } else if (value instanceof File) { file = (File) value; blob = new BlobHelper(new FileInputStream(file), (int) file.length()); } else if (value instanceof String) { file = new File((String) value); blob = new BlobHelper(new FileInputStream(file), (int) file.length()); } else if (value instanceof Part) { Part anyFile = (Part) value; blob = new BlobHelper(new BufferedInputStream(anyFile.getInputStream()), anyFile.getSize()); } else { throw new SQLException("Invalid type for blob: " + value.getClass().getName()); } //InputStream input = new BufferedInputStream(new FileInputStream(file)); statement.setBlob(position, blob); } break; case Types.VARBINARY: //System.out.println("VARBINARY"); if (value instanceof JDBCxlobHelper) { statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream, ((JDBCxlobHelper) value).length); } else if (value instanceof Source) { statement.setBinaryStream(position, ((Source) value).getInputStream(), (int) ((Source) value).getContentLength()); } else if (value instanceof Part) { statement.setBinaryStream(position, ((Part) value).getInputStream(), ((Part) value).getSize()); } else { if (value instanceof File) { file = (File) value; } else if (value instanceof String) { file = new File((String) value); } else { throw new SQLException("Invalid type for blob: " + value.getClass().getName()); } //InputStream input = new BufferedInputStream(new FileInputStream(file)); FileInputStream input = new FileInputStream(file); statement.setBinaryStream(position, input, (int) file.length()); } break; case Types.INTEGER: //System.out.println("INTEGER"); Integer i = null; if (value instanceof Integer) { i = (Integer) value; } else if (value instanceof Number) { i = new Integer(((Number) value).intValue()); } else { i = new Integer(value.toString()); } statement.setInt(position, i.intValue()); break; case Types.BIT: //System.out.println("BIT"); Boolean bo = null; if (value instanceof Boolean) { bo = (Boolean) value; } else if (value instanceof Number) { bo = BooleanUtils.toBooleanObject(((Number) value).intValue() == 1); } else { bo = BooleanUtils.toBooleanObject(value.toString()); } statement.setBoolean(position, bo.booleanValue()); break; default: //System.out.println("default"); throw new SQLException("Impossible exception - invalid type "); } //System.out.println("========================================================================"); }
From source file:org.apache.torque.engine.database.model.TypeMap.java
/** * Initializes the SQL to Java map so that it * can be used by client code./*from w ww. j av a2 s . c o m*/ */ public static synchronized void initialize() { if (!isInitialized) { // Create JDBC -> Java object mappings. jdbcToJavaObjectMap = new Hashtable(); jdbcToJavaObjectMap.put(SchemaType.CHAR, CHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.VARCHAR, VARCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.CLOB, CLOB_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.NUMERIC, NUMERIC_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DECIMAL, DECIMAL_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BIT, BIT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TINYINT, TINYINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.SMALLINT, SMALLINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.INTEGER, INTEGER_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BIGINT, BIGINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.REAL, REAL_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.FLOAT, FLOAT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DOUBLE, DOUBLE_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BINARY, BINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.VARBINARY, VARBINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BLOB, BLOB_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DATE, DATE_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TIME, TIME_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TIMESTAMP, TIMESTAMP_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_OBJECT_TYPE); // Create JDBC -> native Java type mappings. jdbcToJavaNativeMap = new Hashtable(); jdbcToJavaNativeMap.put(SchemaType.CHAR, CHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.VARCHAR, VARCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.CLOB, CLOB_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.NUMERIC, NUMERIC_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DECIMAL, DECIMAL_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BIT, BIT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TINYINT, TINYINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.INTEGER, INTEGER_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BIGINT, BIGINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.REAL, REAL_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.FLOAT, FLOAT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BINARY, BINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.VARBINARY, VARBINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BLOB, BLOB_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DATE, DATE_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TIME, TIME_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TIMESTAMP, TIMESTAMP_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_TYPE); jdbcToJavaNativeObjectMap = new Hashtable(); jdbcToJavaNativeObjectMap.put(SchemaType.BIT, BIT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.TINYINT, TINYINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.INTEGER, INTEGER_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BIGINT, BIGINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.REAL, REAL_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.FLOAT, FLOAT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_OBJECT_TYPE); // Create JDBC -> Village asX() mappings. jdbcToVillageMethodMap = new Hashtable(); jdbcToVillageMethodMap.put(SchemaType.CHAR, CHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.VARCHAR, VARCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.CLOB, CLOB_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.NUMERIC, NUMERIC_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DECIMAL, DECIMAL_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BIT, BIT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.REAL, REAL_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BINARY, BINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.VARBINARY, VARBINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BLOB, BLOB_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DATE, DATE_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TIME, TIME_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_METHOD); jdbcToVillageObjectMethodMap = new Hashtable(); jdbcToVillageObjectMethodMap.put(SchemaType.BIT, BIT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.REAL, REAL_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_OBJECT_METHOD); // Create JDBC -> ParameterParser getX() mappings. jdbcToPPMethodMap = new Hashtable(); jdbcToPPMethodMap.put(SchemaType.CHAR, CHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.VARCHAR, VARCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.NUMERIC, NUMERIC_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DECIMAL, DECIMAL_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BIT, BIT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TINYINT, TINYINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.SMALLINT, SMALLINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.INTEGER, INTEGER_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BIGINT, BIGINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.REAL, REAL_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.FLOAT, FLOAT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DOUBLE, DOUBLE_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BINARY, BINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.VARBINARY, VARBINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DATE, DATE_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TIME, TIME_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_PP_METHOD); // Create JDBC -> Java object mappings. torqueTypeToJdbcTypeMap = new Hashtable(); Iterator iter = SchemaType.iterator(); while (iter.hasNext()) { SchemaType type = (SchemaType) iter.next(); torqueTypeToJdbcTypeMap.put(type, type); } torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANCHAR, SchemaType.CHAR); torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANINT, SchemaType.INTEGER); // Create JDBC type code to torque type map. jdbcToTorqueTypeMap = new Hashtable(); jdbcToTorqueTypeMap.put(new Integer(Types.CHAR), SchemaType.CHAR); jdbcToTorqueTypeMap.put(new Integer(Types.VARCHAR), SchemaType.VARCHAR); jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARCHAR), SchemaType.LONGVARCHAR); jdbcToTorqueTypeMap.put(new Integer(Types.CLOB), SchemaType.CLOB); jdbcToTorqueTypeMap.put(new Integer(Types.NUMERIC), SchemaType.NUMERIC); jdbcToTorqueTypeMap.put(new Integer(Types.DECIMAL), SchemaType.DECIMAL); jdbcToTorqueTypeMap.put(new Integer(Types.BIT), SchemaType.BIT); jdbcToTorqueTypeMap.put(new Integer(Types.TINYINT), SchemaType.TINYINT); jdbcToTorqueTypeMap.put(new Integer(Types.SMALLINT), SchemaType.SMALLINT); jdbcToTorqueTypeMap.put(new Integer(Types.INTEGER), SchemaType.INTEGER); jdbcToTorqueTypeMap.put(new Integer(Types.BIGINT), SchemaType.BIGINT); jdbcToTorqueTypeMap.put(new Integer(Types.REAL), SchemaType.REAL); jdbcToTorqueTypeMap.put(new Integer(Types.FLOAT), SchemaType.FLOAT); jdbcToTorqueTypeMap.put(new Integer(Types.DOUBLE), SchemaType.DOUBLE); jdbcToTorqueTypeMap.put(new Integer(Types.BINARY), SchemaType.BINARY); jdbcToTorqueTypeMap.put(new Integer(Types.VARBINARY), SchemaType.VARBINARY); jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARBINARY), SchemaType.LONGVARBINARY); jdbcToTorqueTypeMap.put(new Integer(Types.BLOB), SchemaType.BLOB); jdbcToTorqueTypeMap.put(new Integer(Types.DATE), SchemaType.DATE); jdbcToTorqueTypeMap.put(new Integer(Types.TIME), SchemaType.TIME); jdbcToTorqueTypeMap.put(new Integer(Types.TIMESTAMP), SchemaType.TIMESTAMP); isInitialized = true; } }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set the values from the Json node to the current object (no database access) * // w w w.j a v a 2 s . c o m * @param node * @param ignorePrimaryKey * True will ignore primaryKey from Json * @throws WaarpDatabaseSqlException */ public void setFromJson(ObjectNode node, boolean ignorePrimaryKey) throws WaarpDatabaseSqlException { DbValue[] list = allFields; if (ignorePrimaryKey) { list = otherFields; } for (DbValue value : list) { if (value.column.equalsIgnoreCase("UPDATEDINFO")) { continue; } JsonNode item = node.get(value.column); if (item != null && !item.isMissingNode() && !item.isNull()) { isSaved = false; switch (value.type) { case Types.VARCHAR: case Types.LONGVARCHAR: value.setValue(item.asText()); break; case Types.BIT: value.setValue(item.asBoolean()); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value.setValue(item.asInt()); break; case Types.BIGINT: value.setValue(item.asLong()); break; case Types.REAL: case Types.DOUBLE: value.setValue(item.asDouble()); break; case Types.VARBINARY: try { value.setValue(item.binaryValue()); } catch (IOException e) { throw new WaarpDatabaseSqlException("Issue while assigning array of bytes", e); } break; case Types.DATE: value.setValue(new Date(item.asLong())); break; case Types.TIMESTAMP: value.setValue(new Timestamp(item.asLong())); break; case Types.CLOB: case Types.BLOB: default: throw new WaarpDatabaseSqlException("Unsupported type: " + value.type); } } } setFromArray(); }
From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java
/** * This method bind values to prepared statement. * * @param type data Type/*w w w . j a v a2 s .co m*/ * @param value String value * @param ordinalPosition Ordinal Position * @param sqlStatement Statement * @throws SQLException * @throws ParseException * @throws ODataServiceFault */ private void bindValuesToPreparedStatement(int type, String value, int ordinalPosition, PreparedStatement sqlStatement) throws SQLException, ParseException, ODataServiceFault { byte[] data; try { switch (type) { case Types.INTEGER: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setInt(ordinalPosition, ConverterUtil.convertToInt(value)); } break; case Types.TINYINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setByte(ordinalPosition, ConverterUtil.convertToByte(value)); } break; case Types.SMALLINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setShort(ordinalPosition, ConverterUtil.convertToShort(value)); } break; case Types.DOUBLE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDouble(ordinalPosition, ConverterUtil.convertToDouble(value)); } break; case Types.VARCHAR: /* fall through */ case Types.CHAR: /* fall through */ case Types.LONGVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; case Types.CLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BOOLEAN: /* fall through */ case Types.BIT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBoolean(ordinalPosition, ConverterUtil.convertToBoolean(value)); } break; case Types.BLOB: /* fall through */ case Types.LONGVARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBlob(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.BINARY: /* fall through */ case Types.VARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBinaryStream(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.DATE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDate(ordinalPosition, DBUtils.getDate(value)); } break; case Types.DECIMAL: /* fall through */ case Types.NUMERIC: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBigDecimal(ordinalPosition, ConverterUtil.convertToBigDecimal(value)); } break; case Types.FLOAT: /* fall through */ case Types.REAL: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setFloat(ordinalPosition, ConverterUtil.convertToFloat(value)); } break; case Types.TIME: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTime(ordinalPosition, DBUtils.getTime(value)); } break; case Types.LONGNVARCHAR: /* fall through */ case Types.NCHAR: /* fall through */ case Types.NVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNString(ordinalPosition, value); } break; case Types.NCLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BIGINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setLong(ordinalPosition, ConverterUtil.convertToLong(value)); } break; case Types.TIMESTAMP: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTimestamp(ordinalPosition, DBUtils.getTimestamp(value)); } break; default: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; } } catch (DataServiceFault e) { throw new ODataServiceFault(e, "Error occurred while binding values. :" + e.getMessage()); } }
From source file:org.jumpmind.symmetric.db.sqlanywhere.SqlAnywhereTriggerTemplate.java
@Override protected String buildKeyVariablesDeclare(Column[] columns, String prefix) { String text = ""; for (int i = 0; i < columns.length; i++) { text += "declare @" + prefix + "pk" + i + " "; switch (columns[i].getMappedTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: text += "bigint\n"; break; case Types.NUMERIC: case Types.DECIMAL: text += "decimal\n"; break; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: text += "float\n"; break; case Types.CHAR: case Types.VARCHAR: case ColumnTypes.NVARCHAR: case ColumnTypes.LONGNVARCHAR: case Types.LONGVARCHAR: text += "varchar(1000)\n"; break; case Types.DATE: text += "date\n"; break; case Types.TIME: text += "time\n"; break; case Types.TIMESTAMP: text += "datetime\n"; break; case Types.BOOLEAN: case Types.BIT: text += "bit\n"; break; case Types.CLOB: text += "varchar(16384)\n"; break; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case -10: // SQL-Server ntext binary type text += "varbinary(16384)\n"; break; case Types.OTHER: text += "varbinary(16384)\n"; break; default://from w w w.ja v a 2s . c o m if (columns[i].getJdbcTypeName() != null && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) { text += "interval"; break; } throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType()); } } return text; }
From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java
protected void setStatementParameter(int parameterIndex, Class<?> parameterType, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (java.lang.Boolean.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.BIT); } else {/*from w ww. ja v a 2 s . c o m*/ statement.setBoolean(parameterIndex, (Boolean) parameterValue); } } else if (java.lang.Byte.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.TINYINT); } else { statement.setByte(parameterIndex, (Byte) parameterValue); } } else if (java.lang.Double.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DOUBLE); } else { statement.setDouble(parameterIndex, (Double) parameterValue); } } else if (java.lang.Float.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.FLOAT); } else { statement.setFloat(parameterIndex, (Float) parameterValue); } } else if (java.lang.Integer.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.INTEGER); } else { statement.setInt(parameterIndex, (Integer) parameterValue); } } else if (java.lang.Long.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.BIGINT); } else { statement.setLong(parameterIndex, (Long) parameterValue); } } else if (java.lang.Short.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.SMALLINT); } else { statement.setShort(parameterIndex, (Short) parameterValue); } } else if (java.math.BigDecimal.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DECIMAL); } else { statement.setBigDecimal(parameterIndex, (BigDecimal) parameterValue); } } else if (java.lang.String.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.VARCHAR); } else { statement.setString(parameterIndex, parameterValue.toString()); } } else if (java.sql.Timestamp.class.isAssignableFrom(parameterType)) { setTimestamp(parameterIndex, parameterValue, properties); } else if (java.sql.Time.class.isAssignableFrom(parameterType)) { setTime(parameterIndex, parameterValue, properties); } else if (java.util.Date.class.isAssignableFrom(parameterType)) { setDate(parameterIndex, parameterValue, properties); } else { if (isProcedureCall) { boolean handled = procedureCallHandler.setParameterValue(parameterIndex, parameterType, parameterValue); if (handled) { return; } } if (parameterValue == null) { statement.setNull(parameterIndex, Types.JAVA_OBJECT); } else { statement.setObject(parameterIndex, parameterValue); } } }