List of usage examples for java.sql Types BLOB
int BLOB
To view the source code for java.sql Types BLOB.
Click Source Link
BLOB
. From source file:org.apache.sqoop.manager.ConnManager.java
/** * Resolve a database-specific type to Avro data type. * @param sqlType sql type//from ww w . j ava 2 s .c om * @return avro type */ public Type toAvroType(int sqlType) { switch (sqlType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return Type.INT; case Types.BIGINT: return Type.LONG; case Types.BIT: case Types.BOOLEAN: return Type.BOOLEAN; case Types.REAL: return Type.FLOAT; case Types.FLOAT: case Types.DOUBLE: return Type.DOUBLE; case Types.NUMERIC: case Types.DECIMAL: return Type.STRING; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: return Type.STRING; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return Type.STRING; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return Type.BYTES; default: throw new IllegalArgumentException("Cannot convert SQL type " + sqlType); } }
From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java
protected void updateImageImputStream(LogoImage logoImage, InputStream inputStream) { getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.DELETE_LOGO_IMAGE_DATA_BY_ID").getSql(), new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId())); if (getExtendedJdbcTemplate().getDatabaseType() == DatabaseType.oracle) { getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.INSERT_EMPTY_LOGO_IMAGE_DATA").getSql(), new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId())); getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.UPDATE_LOGO_IMAGE_DATA").getSql(), new Object[] { new SqlLobValue(inputStream, logoImage.getImageSize(), getLobHandler()), logoImage.getLogoId() }, new int[] { Types.BLOB, Types.NUMERIC }); } else {/*from w ww . j a v a2 s . c o m*/ getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.INSERT_LOGO_IMAGE_DATA").getSql(), new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId()), new SqlParameterValue(Types.BLOB, new SqlLobValue(inputStream, logoImage.getImageSize(), getLobHandler()))); } }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
private void initDialect(DatabaseIdiom idiom) { databaseIdiom = idiom;/*from w ww . ja v a2 s . c o m*/ try { addTranslation("bigint", idiom.getTypeName(Types.BIGINT)); addTranslation("binary", idiom.getTypeName(Types.BINARY)); addTranslation("bit", idiom.getTypeName(Types.BIT)); addTranslation("blob", idiom.getTypeName(Types.BLOB)); addTranslation("boolean", idiom.getTypeName(Types.BOOLEAN)); addTranslation("char", idiom.getTypeName(Types.CHAR)); addTranslation("clob", idiom.getTypeName(Types.CLOB)); addTranslation("date", idiom.getTypeName(Types.DATE)); addTranslation("decimal", idiom.getTypeName(Types.DECIMAL)); addTranslation("double", idiom.getTypeName(Types.DOUBLE)); addTranslation("float", idiom.getTypeName(Types.FLOAT)); addTranslation("integer", idiom.getTypeName(Types.INTEGER)); addTranslation("longnvarchar", idiom.getTypeName(Types.LONGNVARCHAR)); addTranslation("longvarbinary", idiom.getTypeName(Types.LONGVARBINARY)); addTranslation("longvarchar", idiom.getTypeName(Types.LONGVARCHAR)); addTranslation("nchar", idiom.getTypeName(Types.NCHAR)); addTranslation("nclob", idiom.getTypeName(Types.NCLOB)); addTranslation("numeric", idiom.getTypeName(Types.NUMERIC)); addTranslation("nvarchar", idiom.getTypeName(Types.NVARCHAR)); addTranslation("real", idiom.getTypeName(Types.REAL)); addTranslation("smallint", idiom.getTypeName(Types.SMALLINT)); addTranslation("time", idiom.getTypeName(Types.TIME)); addTranslation("timestamp", idiom.getTypeName(Types.TIMESTAMP)); addTranslation("tinyint", idiom.getTypeName(Types.TINYINT)); addTranslation("varbinary", idiom.getTypeName(Types.VARBINARY)); databaseIdiom.initDialect(translations, workarounds); // Ignore autogenerated ID's addWorkaround("generated always as identity", ""); } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:oscar.util.SqlUtils.java
/** * this utility-method assigns a particular value to a place holder of a PreparedStatement. it tries to find the correct setXxx() value, accoring to the field-type information * represented by "fieldType". quality: this method is bloody alpha (as you migth see :=) *//*from ww w . j av a 2 s. c o m*/ public static void fillPreparedStatement(PreparedStatement ps, int col, Object val, int fieldType) throws SQLException { try { logger.info("fillPreparedStatement( ps, " + col + ", " + val + ", " + fieldType + ")..."); Object value = null; // Check for hard-coded NULL if (!("$null$".equals(val))) { value = val; } if (value != null) { switch (fieldType) { case FieldTypes.INTEGER: ps.setInt(col, Integer.parseInt((String) value)); break; case FieldTypes.NUMERIC: ps.setBigDecimal(col, createAppropriateNumeric(value)); break; case FieldTypes.CHAR: ps.setString(col, (String) value); break; case FieldTypes.DATE: ps.setDate(col, createAppropriateDate(value)); break; // #checkme case FieldTypes.TIMESTAMP: ps.setTimestamp(col, java.sql.Timestamp.valueOf((String) value)); break; case FieldTypes.DOUBLE: ps.setDouble(col, Double.valueOf((String) value).doubleValue()); break; case FieldTypes.FLOAT: ps.setFloat(col, Float.valueOf((String) value).floatValue()); break; case FieldTypes.LONG: ps.setLong(col, Long.parseLong(String.valueOf(value))); break; case FieldTypes.BLOB: FileHolder fileHolder = (FileHolder) value; try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(fileHolder); out.flush(); byte[] buf = byteOut.toByteArray(); byteOut.close(); out.close(); ByteArrayInputStream bytein = new ByteArrayInputStream(buf); int byteLength = buf.length; ps.setBinaryStream(col, bytein, byteLength); // store fileHolder as a whole (this way we don't lose file meta-info!) } catch (IOException ioe) { MiscUtils.getLogger().error("Error", ioe); logger.info(ioe.toString()); throw new SQLException("error storing BLOB in database - " + ioe.toString(), null, 2); } break; case FieldTypes.DISKBLOB: ps.setString(col, (String) value); break; default: ps.setObject(col, value); // #checkme } } else { switch (fieldType) { case FieldTypes.INTEGER: ps.setNull(col, java.sql.Types.INTEGER); break; case FieldTypes.NUMERIC: ps.setNull(col, java.sql.Types.NUMERIC); break; case FieldTypes.CHAR: ps.setNull(col, java.sql.Types.CHAR); break; case FieldTypes.DATE: ps.setNull(col, java.sql.Types.DATE); break; case FieldTypes.TIMESTAMP: ps.setNull(col, java.sql.Types.TIMESTAMP); break; case FieldTypes.DOUBLE: ps.setNull(col, java.sql.Types.DOUBLE); break; case FieldTypes.FLOAT: ps.setNull(col, java.sql.Types.FLOAT); break; case FieldTypes.BLOB: ps.setNull(col, java.sql.Types.BLOB); case FieldTypes.DISKBLOB: ps.setNull(col, java.sql.Types.CHAR); default: ps.setNull(col, java.sql.Types.OTHER); } } } catch (Exception e) { throw new SQLException("Field type seems to be incorrect - " + e.toString(), null, 1); } }
From source file:architecture.ee.web.community.profile.dao.jdbc.JdbcProfileDao.java
protected void updateProfileImageImputStream(ProfileImage image, InputStream inputStream) { getExtendedJdbcTemplate().update(//from w w w . j a va2 s . c o m getBoundSql("ARCHITECTURE_COMMUNITY.DELETE_PROFILE_IMAGE_DATA_BY_ID").getSql(), new SqlParameterValue(Types.NUMERIC, image.getProfileImageId())); if (getExtendedJdbcTemplate().getDatabaseType() == DatabaseType.oracle) { getExtendedJdbcTemplate().update( getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_EMPTY_PROFILE_IMAGE_DATA").getSql(), new SqlParameterValue(Types.NUMERIC, image.getProfileImageId())); getExtendedJdbcTemplate().update( getBoundSql("ARCHITECTURE_COMMUNITY.UPDATE_PROFILE_IMAGE_DATA").getSql(), new Object[] { new SqlLobValue(inputStream, image.getImageSize(), getLobHandler()), image.getProfileImageId() }, new int[] { Types.BLOB, Types.NUMERIC }); } else { getExtendedJdbcTemplate().update( getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_PROFILE_IMAGE_DATA").getSql(), new SqlParameterValue(Types.NUMERIC, image.getProfileImageId()), new SqlParameterValue( Types.BLOB, new SqlLobValue(inputStream, image.getImageSize(), getLobHandler()))); } }
From source file:com.bt.aloha.dao.StateInfoDaoImpl.java
public void replace(final T info) { if (info == null) throw new IllegalArgumentException("Cannot replace null info object in collection."); T newInfo = info.cloneObject();/*from w w w . j a v a 2 s .c om*/ newInfo.updateVersionId(); newInfo.updateLastUsedTime(); int updated = 0; try { Object[] params = new Object[] { newInfo.getVersionId(), newInfo.getLastUsedTime(), newInfo.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(newInfo)), info.getId(), info.getVersionId(), }; int[] types = new int[] { Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB, Types.VARCHAR, Types.VARCHAR }; updated = getJdbcTemplate().update(UPDATE_SQL, params, types); } catch (DataAccessException e) { throw new IllegalArgumentException(String.format("Cannot update info %s in database", info.getId()), e); } if (updated == 0) throw new ConcurrentUpdateException(info.getId(), String.format("Info %s modified in database, try again", info.getId())); info.setVersionId(newInfo.getVersionId()); info.setLastUsedTime(newInfo.getLastUsedTime()); }
From source file:com.alibaba.otter.node.etl.extract.DatabaseExtractorTest.java
private List<EventColumn> getColumn(int value) { List<EventColumn> result = new ArrayList<EventColumn>(); result.add(buildColumn("id", Types.INTEGER, "" + value, true, false)); result.add(buildColumn("name", Types.VARCHAR, "ljh_" + value, true, false)); result.add(buildColumn("alias_name", Types.CHAR, "hello_" + value, false, false)); result.add(buildColumn("amount", Types.DECIMAL, "100.01", false, false)); result.add(buildColumn("text_b", Types.BLOB, "[116,101,120,116,95,98]", false, false)); result.add(buildColumn("text_c", Types.CLOB, "", false, false)); result.add(buildColumn("curr_date", Types.DATE, "2011-01-01", false, false)); result.add(buildColumn("gmt_create", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false)); result.add(buildColumn("gmt_modify", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false)); return result; }
From source file:at.bestsolution.persistence.java.Util.java
public static void setValue(PreparedStatement pstmt, int parameterIndex, TypedValue value) throws SQLException { if (value.value == null) { int sqlType; switch (value.type) { case INT: sqlType = Types.INTEGER; break; case DOUBLE: sqlType = Types.DECIMAL; break; case FLOAT: sqlType = Types.FLOAT; break; case BOOLEAN: sqlType = Types.BOOLEAN; break; case LONG: sqlType = Types.BIGINT; break; case STRING: sqlType = Types.VARCHAR; break; case BLOB: sqlType = Types.BLOB; break; case CLOB: sqlType = Types.CLOB; break; case TIMESTAMP: sqlType = Types.TIMESTAMP; break; default:/*w w w . ja v a 2s . c o m*/ sqlType = Types.OTHER; break; } pstmt.setNull(parameterIndex, sqlType); } else { switch (value.type) { case INT: pstmt.setInt(parameterIndex, ((Number) value.value).intValue()); break; case DOUBLE: pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue()); break; case FLOAT: pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue()); break; case BOOLEAN: pstmt.setBoolean(parameterIndex, Boolean.TRUE.equals(value.value)); break; case LONG: pstmt.setLong(parameterIndex, ((Number) value.value).longValue()); break; case STRING: pstmt.setString(parameterIndex, (String) value.value); break; case TIMESTAMP: if (value.value instanceof Timestamp) { pstmt.setTimestamp(parameterIndex, (Timestamp) value.value); } else { pstmt.setTimestamp(parameterIndex, new Timestamp(((Date) value.value).getTime())); } break; case UNKNOWN: pstmt.setObject(parameterIndex, value.value); break; default: throw new IllegalStateException("Unknown type"); } } }
From source file:org.xsystem.sql2.dml.DmlCommand.java
Object getValue(Object retValue, int jdbcType, String objectType, Connection con, AbstactNativeHelper nativeHelper) throws SQLException { if (jdbcType == Types.ARRAY && retValue != null) { Array array = (Array) retValue; retValue = nativeHelper.createList(con, array, objectType); } else if (jdbcType == Types.STRUCT && retValue != null) { Struct structValue = (Struct) retValue; retValue = nativeHelper.createMap(con, structValue, objectType); } else if (jdbcType == Types.BLOB && retValue != null) { Blob blob = (Blob) retValue; retValue = getBlob(blob);/*from w ww . j av a2 s . co m*/ } else if (jdbcType == Types.CLOB && retValue != null) { Clob clob = (Clob) retValue; retValue = getClob(clob); } else if (jdbcType == Types.OTHER && retValue != null) { retValue = nativeHelper.getOTHER(con, retValue); } return retValue; }
From source file:org.executequery.gui.resultset.ResultSetTableModel.java
public void createTable(ResultSet resultSet) { if (!isOpenAndValid(resultSet)) { clearData();//from w w w . j av a2 s. co m return; } try { resetMetaData(); ResultSetMetaData rsmd = resultSet.getMetaData(); columnHeaders.clear(); visibleColumnHeaders.clear(); tableData.clear(); int zeroBaseIndex = 0; int count = rsmd.getColumnCount(); for (int i = 1; i <= count; i++) { zeroBaseIndex = i - 1; columnHeaders.add(new ResultSetColumnHeader(zeroBaseIndex, rsmd.getColumnLabel(i), rsmd.getColumnName(i), rsmd.getColumnType(i), rsmd.getColumnTypeName(i))); } int recordCount = 0; interrupted = false; if (holdMetaData) { setMetaDataVectors(rsmd); } List<RecordDataItem> rowData; long time = System.currentTimeMillis(); while (resultSet.next()) { if (interrupted || Thread.interrupted()) { throw new InterruptedException(); } recordCount++; rowData = new ArrayList<RecordDataItem>(count); for (int i = 1; i <= count; i++) { zeroBaseIndex = i - 1; ResultSetColumnHeader header = columnHeaders.get(zeroBaseIndex); RecordDataItem value = recordDataItemFactory.create(header); try { int dataType = header.getDataType(); switch (dataType) { // some drivers (informix for example) // was noticed to return the hashcode from // getObject for -1 data types (eg. longvarchar). // force string for these - others stick with // getObject() for default value formatting case Types.CHAR: case Types.VARCHAR: value.setValue(resultSet.getString(i)); break; case Types.DATE: value.setValue(resultSet.getDate(i)); break; case Types.TIME: value.setValue(resultSet.getTime(i)); break; case Types.TIMESTAMP: value.setValue(resultSet.getTimestamp(i)); break; case Types.LONGVARCHAR: case Types.CLOB: value.setValue(resultSet.getClob(i)); break; case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: value.setValue(resultSet.getBytes(i)); break; case Types.BLOB: value.setValue(resultSet.getBlob(i)); break; case Types.BIT: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: case Types.NULL: case Types.OTHER: case Types.JAVA_OBJECT: case Types.DISTINCT: case Types.STRUCT: case Types.ARRAY: case Types.REF: case Types.DATALINK: case Types.BOOLEAN: case Types.ROWID: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: case Types.NCLOB: case Types.SQLXML: // use getObject for all other known types value.setValue(resultSet.getObject(i)); break; default: // otherwise try as string asStringOrObject(value, resultSet, i); break; } } catch (Exception e) { try { // ... and on dump, resort to string value.setValue(resultSet.getString(i)); } catch (SQLException sqlException) { // catch-all SQLException - yes, this is hideous // noticed with invalid date formatted values in mysql value.setValue("<Error - " + sqlException.getMessage() + ">"); } } if (resultSet.wasNull()) { value.setNull(); } rowData.add(value); } tableData.add(rowData); if (recordCount == maxRecords) { break; } } if (Log.isTraceEnabled()) { Log.trace("Finished populating table model - " + recordCount + " rows - [ " + MiscUtils.formatDuration(System.currentTimeMillis() - time) + "]"); } fireTableStructureChanged(); } catch (SQLException e) { System.err.println("SQL error populating table model at: " + e.getMessage()); Log.debug("Table model error - " + e.getMessage(), e); } catch (Exception e) { if (e instanceof InterruptedException) { Log.debug("ResultSet generation interrupted.", e); } else { String message = e.getMessage(); if (StringUtils.isBlank(message)) { System.err.println("Exception populating table model."); } else { System.err.println("Exception populating table model at: " + message); } Log.debug("Table model error - ", e); } } finally { if (resultSet != null) { try { resultSet.close(); Statement statement = resultSet.getStatement(); if (statement != null) { statement.close(); } } catch (SQLException e) { } } } }