List of usage examples for java.sql Types TIME
int TIME
To view the source code for java.sql Types TIME.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME
.
From source file:org.hxzon.util.db.springjdbc.StatementCreatorUtils.java
private static void setValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName, Integer scale, Object inValue) throws SQLException { if (inValue instanceof SqlTypeValue) { ((SqlTypeValue) inValue).setTypeValue(ps, paramIndex, sqlType, typeName); } else if (inValue instanceof SqlValue) { ((SqlValue) inValue).setValue(ps, paramIndex); } else if (sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR || (sqlType == Types.CLOB && isStringValue(inValue.getClass()))) { ps.setString(paramIndex, inValue.toString()); } else if (sqlType == Types.DECIMAL || sqlType == Types.NUMERIC) { if (inValue instanceof BigDecimal) { ps.setBigDecimal(paramIndex, (BigDecimal) inValue); } else if (scale != null) { ps.setObject(paramIndex, inValue, sqlType, scale); } else {/*from ww w. j av a2s. c o m*/ ps.setObject(paramIndex, inValue, sqlType); } } else if (sqlType == Types.DATE) { if (inValue instanceof java.util.Date) { if (inValue instanceof java.sql.Date) { ps.setDate(paramIndex, (java.sql.Date) inValue); } else { ps.setDate(paramIndex, new java.sql.Date(((java.util.Date) inValue).getTime())); } } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setDate(paramIndex, new java.sql.Date(cal.getTime().getTime()), cal); } else { ps.setObject(paramIndex, inValue, Types.DATE); } } else if (sqlType == Types.TIME) { if (inValue instanceof java.util.Date) { if (inValue instanceof java.sql.Time) { ps.setTime(paramIndex, (java.sql.Time) inValue); } else { ps.setTime(paramIndex, new java.sql.Time(((java.util.Date) inValue).getTime())); } } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setTime(paramIndex, new java.sql.Time(cal.getTime().getTime()), cal); } else { ps.setObject(paramIndex, inValue, Types.TIME); } } else if (sqlType == Types.TIMESTAMP) { if (inValue instanceof java.util.Date) { if (inValue instanceof java.sql.Timestamp) { ps.setTimestamp(paramIndex, (java.sql.Timestamp) inValue); } else { ps.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) inValue).getTime())); } } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal); } else { ps.setObject(paramIndex, inValue, Types.TIMESTAMP); } } else if (sqlType == SqlTypeValue.TYPE_UNKNOWN) { if (isStringValue(inValue.getClass())) { ps.setString(paramIndex, inValue.toString()); } else if (isDateValue(inValue.getClass())) { ps.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) inValue).getTime())); } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal); } else { // Fall back to generic setObject call without SQL type specified. ps.setObject(paramIndex, inValue); } } else { // Fall back to generic setObject call with SQL type specified. ps.setObject(paramIndex, inValue, sqlType); } }
From source file:com.mapd.utility.SQLImporter.java
private String getColType(int cType, int precision, int scale) { if (precision > 19) { precision = 19;/* www . j a va 2 s .c om*/ } if (scale > 19) { scale = 18; } switch (cType) { case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: return ("SMALLINT"); case java.sql.Types.INTEGER: return ("INTEGER"); case java.sql.Types.BIGINT: return ("BIGINT"); case java.sql.Types.FLOAT: return ("FLOAT"); case java.sql.Types.DECIMAL: return ("DECIMAL(" + precision + "," + scale + ")"); case java.sql.Types.DOUBLE: return ("DOUBLE"); case java.sql.Types.REAL: return ("REAL"); case java.sql.Types.NUMERIC: return ("NUMERIC(" + precision + "," + scale + ")"); case java.sql.Types.TIME: return ("TIME"); case java.sql.Types.TIMESTAMP: return ("TIMESTAMP"); case java.sql.Types.DATE: return ("DATE"); case java.sql.Types.BOOLEAN: case java.sql.Types.BIT: // deal with postgress treating boolean as bit... this will bite me return ("BOOLEAN"); case java.sql.Types.NVARCHAR: case java.sql.Types.VARCHAR: case java.sql.Types.NCHAR: case java.sql.Types.CHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.LONGNVARCHAR: return ("TEXT ENCODING DICT"); default: throw new AssertionError("Column type " + cType + " not Supported"); } }
From source file:org.apache.oozie.command.SchemaCheckXCommand.java
private String getSQLTypeFromInt(int t) { switch (t) {// w w w .j ava 2 s .c om case Types.BIT: return "BIT"; case Types.TINYINT: return "TINYINT"; case Types.SMALLINT: return "SMALLINT"; case Types.INTEGER: return "INTEGER"; case Types.BIGINT: return "BIGINT"; case Types.FLOAT: return "FLOAT"; case Types.REAL: return "REAL"; case Types.DOUBLE: return "DOUBLE"; case Types.NUMERIC: return "NUMERIC"; case Types.DECIMAL: return "DECIMAL"; case Types.CHAR: return "CHAR"; case Types.VARCHAR: return "VARCHAR"; case Types.LONGVARCHAR: return "LONGVARCHAR"; case Types.DATE: return "DATE"; case Types.TIME: return "TIME"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.BINARY: return "BINARY"; case Types.VARBINARY: return "VARBINARY"; case Types.LONGVARBINARY: return "LONGVARBINARY"; case Types.NULL: return "NULL"; case Types.OTHER: return "OTHER"; case Types.JAVA_OBJECT: return "JAVA_OBJECT"; case Types.DISTINCT: return "DISTINCT"; case Types.STRUCT: return "STRUCT"; case Types.ARRAY: return "ARRAY"; case Types.BLOB: return "BLOB"; case Types.CLOB: return "CLOB"; case Types.REF: return "REF"; case Types.DATALINK: return "DATALINK"; case Types.BOOLEAN: return "BOOLEAN"; case Types.ROWID: return "ROWID"; case Types.NCHAR: return "NCHAR"; case Types.NVARCHAR: return "NVARCHAR"; case Types.LONGNVARCHAR: return "LONGNVARCHAR"; case Types.NCLOB: return "NCLOB"; case Types.SQLXML: return "SQLXML"; default: return "unknown"; } }
From source file:org.executequery.gui.importexport.AbstractImportExportWorker.java
/** * Sets the specified value in the specified position for the * specified java.sql.Type within the prepared statement. * * @param value - the value/*w w w . j a v a 2 s . com*/ * @param index - the position within the statement * @param sqlType - the SQL type * @param trim - whether to trim the whitespace from the value * @param df - the DataFormat object for date values */ protected void setValue(String value, int index, int sqlType, boolean trim, DateFormat df) throws Exception { if (value == null) { prepStmnt.setNull(index, sqlType); } else { switch (sqlType) { case Types.TINYINT: byte _byte = Byte.valueOf(value).byteValue(); prepStmnt.setShort(index, _byte); break; case Types.BIGINT: long _long = Long.valueOf(value).longValue(); prepStmnt.setLong(index, _long); break; case Types.SMALLINT: short _short = Short.valueOf(value).shortValue(); prepStmnt.setShort(index, _short); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: if (trim) { value = value.trim(); } prepStmnt.setString(index, value); break; case Types.BIT: case Types.BOOLEAN: String booleanValue = value; if ("t".equalsIgnoreCase(value)) { booleanValue = "true"; } else if ("f".equalsIgnoreCase(value)) { booleanValue = "false"; } boolean _boolean = Boolean.valueOf(booleanValue).booleanValue(); prepStmnt.setBoolean(index, _boolean); break; case Types.NUMERIC: case Types.DECIMAL: prepStmnt.setBigDecimal(index, new BigDecimal(value)); break; case Types.REAL: float _float = Float.valueOf(value).floatValue(); prepStmnt.setFloat(index, _float); break; case Types.FLOAT: case Types.DOUBLE: prepStmnt.setDouble(index, Double.parseDouble(value)); break; case Types.INTEGER: prepStmnt.setInt(index, Integer.parseInt(value)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: // if the date format is null, insert as a char value if (df != null) { java.util.Date j_datetime = df.parse(value); prepStmnt.setDate(index, new java.sql.Date(j_datetime.getTime())); } else { try { prepStmnt.setObject(index, value, sqlType); /* if (sqlType == Types.TIMESTAMP) { prepStmnt.setTimestamp(index, java.sql.Timestamp.valueOf(value)); } else if (sqlType == Types.TIME) { prepStmnt.setTime(index, java.sql.Time.valueOf(value)); } else { prepStmnt.setDate(index, java.sql.Date.valueOf(value)); } */ } // want a more useful message here than what will likely // be returned due to internal driver code on formatting // a SQL date value from string // (ie. could be parsing error, number format etc...) catch (Exception e) { throw new IllegalArgumentException("[ " + MiscUtils.getExceptionName(e) + " ] " + getBundle().getString("AbstractImportExportWorker.dateConversionError")); } } break; case Types.LONGVARBINARY: case Types.BINARY: case Types.BLOB: case Types.CLOB: prepStmnt.setBytes(index, Base64.decode(value)); break; default: prepStmnt.setObject(index, value); break; } } }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
protected Object getObjectValue(String value, Column column, BinaryEncoding encoding, boolean useVariableDates, boolean fitToColumn) throws DecoderException { Object objectValue = value;// ww w .j a va2s. c o m int type = column.getMappedTypeCode(); if ((value == null || (getDdlBuilder().getDatabaseInfo().isEmptyStringNulled() && value.equals(""))) && column.isRequired() && column.isOfTextType()) { objectValue = REQUIRED_FIELD_NULL_SUBSTITUTE; } if (value != null) { if (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME) { objectValue = parseDate(type, value, useVariableDates); } else if (type == Types.CHAR) { String charValue = value.toString(); if ((StringUtils.isBlank(charValue) && getDdlBuilder().getDatabaseInfo().isBlankCharColumnSpacePadded()) || (StringUtils.isNotBlank(charValue) && getDdlBuilder().getDatabaseInfo().isNonBlankCharColumnSpacePadded())) { objectValue = StringUtils.rightPad(value.toString(), column.getSizeAsInt(), ' '); } } else if (type == Types.BIGINT) { objectValue = parseBigInteger(value); } else if (type == Types.INTEGER || type == Types.SMALLINT || type == Types.BIT || type == Types.TINYINT) { objectValue = parseInteger(value); } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.FLOAT || type == Types.DOUBLE || type == Types.REAL) { objectValue = parseBigDecimal(value); } else if (type == Types.BOOLEAN) { objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE; } else if (!(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY)) && !(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY)) && (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY || // SQLServer ntext type type == -10)) { if (encoding == BinaryEncoding.NONE) { objectValue = value.getBytes(); } else if (encoding == BinaryEncoding.BASE64) { objectValue = Base64.decodeBase64(value.getBytes()); } else if (encoding == BinaryEncoding.HEX) { objectValue = Hex.decodeHex(value.toCharArray()); } } else if (type == Types.ARRAY) { objectValue = createArray(column, value); } } if (objectValue instanceof String) { String stringValue = cleanTextForTextBasedColumns((String) objectValue); int size = column.getSizeAsInt(); if (fitToColumn && size > 0 && stringValue.length() > size) { stringValue = stringValue.substring(0, size); } objectValue = stringValue; } return objectValue; }
From source file:org.eclipse.ecr.core.storage.sql.extensions.H2Fulltext.java
protected static String asString(Object data, int type) throws SQLException { if (data == null) { return ""; }//from www . ja va 2 s. co m switch (type) { case Types.BIT: case DataType.TYPE_BOOLEAN: case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: case Types.TINYINT: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: return data.toString(); case Types.CLOB: try { if (data instanceof Clob) { data = ((Clob) data).getCharacterStream(); } return IOUtils.readStringAndClose((Reader) data, -1); } catch (IOException e) { throw Message.convert(e); } case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BINARY: case Types.JAVA_OBJECT: case Types.OTHER: case Types.BLOB: case Types.STRUCT: case Types.REF: case Types.NULL: case Types.ARRAY: case DataType.TYPE_DATALINK: case Types.DISTINCT: throw new SQLException("Unsupported column data type: " + type); default: return ""; } }
From source file:com.squid.core.domain.operators.ExtendedType.java
public static IDomain computeDomain(int data_type, int size, int scale) { switch (data_type) { case Types.BOOLEAN: case Types.BIT:// on PG systems, this is how a boolean is actually represented by the driver return IDomain.BOOLEAN; case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: return IDomain.NUMERIC; /////////////////////////// case Types.REAL: case Types.DOUBLE: case Types.FLOAT: return IDomain.CONTINUOUS; case Types.NUMERIC: case Types.DECIMAL: return scale > 0 || size == 0 ? IDomain.CONTINUOUS : IDomain.NUMERIC; case Types.CHAR: case Types.NCHAR: case Types.VARCHAR: case Types.NVARCHAR: case Types.LONGVARCHAR: case Types.CLOB: return IDomain.STRING; /////////////////////////// case Types.TIME: return IDomain.TIME; case Types.DATE: return IDomain.DATE; case Types.TIMESTAMP: return IDomain.TIMESTAMP; /////////////////////////// default:/*from w w w . java 2s . com*/ return IDomain.UNKNOWN; } }
From source file:org.sakaiproject.webservices.SakaiReport.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;//from w w w .j av a2 s . co m case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; case Types.VARBINARY: case Types.BINARY: value = handleRaw(rs.getBytes(colIndex)); break; default: value = ""; } if (value == null) { value = ""; } return value; }
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// w w w. j a v a 2 s. c o m */ 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:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
public static String getPartitionSizeValidationError(int colType, String column, String partitionSize) { switch (colType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: try {//from w w w. j a v a 2 s . co m int intVal = Integer.parseInt(partitionSize); if (intVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.BIGINT: // TIME, DATE, and TIMESTAMP are represented as long (epoch) case Types.TIME: case Types.DATE: case Types.TIMESTAMP: try { long longVal = Long.parseLong(partitionSize); if (longVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.FLOAT: case Types.REAL: try { float floatVal = Float.parseFloat(partitionSize); if (floatVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.DOUBLE: try { double doubleVal = Double.parseDouble(partitionSize); if (doubleVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.NUMERIC: case Types.DECIMAL: try { BigDecimal decimalValue = new BigDecimal(partitionSize); if (decimalValue.signum() < 1) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; } return null; }