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:com.cloudera.sqoop.manager.SqlManager.java
/** * Resolve a database-specific type to the Java type that should contain it. * @param sqlType/*from ww w . j av a2 s . co m*/ * @return the name of a Java type to hold the sql datatype, or null if none. */ public String toJavaType(int sqlType) { // Mappings taken from: // http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html if (sqlType == Types.INTEGER) { return "Integer"; } else if (sqlType == Types.VARCHAR) { return "String"; } else if (sqlType == Types.CHAR) { return "String"; } else if (sqlType == Types.LONGVARCHAR) { return "String"; } else if (sqlType == Types.NUMERIC) { return "java.math.BigDecimal"; } else if (sqlType == Types.DECIMAL) { return "java.math.BigDecimal"; } else if (sqlType == Types.BIT) { return "Boolean"; } else if (sqlType == Types.BOOLEAN) { return "Boolean"; } else if (sqlType == Types.TINYINT) { return "Integer"; } else if (sqlType == Types.SMALLINT) { return "Integer"; } else if (sqlType == Types.BIGINT) { return "Long"; } else if (sqlType == Types.REAL) { return "Float"; } else if (sqlType == Types.FLOAT) { return "Double"; } else if (sqlType == Types.DOUBLE) { return "Double"; } else if (sqlType == Types.DATE) { return "java.sql.Date"; } else if (sqlType == Types.TIME) { return "java.sql.Time"; } else if (sqlType == Types.TIMESTAMP) { return "java.sql.Timestamp"; } else if (sqlType == Types.BINARY || sqlType == Types.VARBINARY) { return BytesWritable.class.getName(); } else if (sqlType == Types.CLOB) { return ClobRef.class.getName(); } else if (sqlType == Types.BLOB || sqlType == Types.LONGVARBINARY) { return BlobRef.class.getName(); } else { // TODO(aaron): Support DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT. // Return null indicating database-specific manager should return a // java data type if it can find one for any nonstandard type. return null; } }
From source file:org.apache.openjpa.jdbc.sql.SybaseDictionary.java
@Override public String getIsNullSQL(String colAlias, int colType) { switch (colType) { case Types.BLOB: case Types.CLOB: return String.format("datalength(%s) = 0", colAlias); }/* w w w . jav a 2 s . co m*/ return super.getIsNullSQL(colAlias, colType); }
From source file:com.opengamma.masterdb.security.DbSecurityMaster.java
private void storeRawSecurityDetail(RawSecurity security) { final DbMapSqlParameterSource rawArgs = new DbMapSqlParameterSource() .addValue("security_id", extractRowId(security.getUniqueId())).addValue("raw_data", new SqlLobValue(security.getRawData(), getDialect().getLobHandler()), Types.BLOB); final String sqlRaw = getElSqlBundle().getSql("InsertRaw", rawArgs); getJdbcTemplate().update(sqlRaw, rawArgs); }
From source file:org.apache.openjpa.jdbc.sql.SybaseDictionary.java
@Override public String getIsNotNullSQL(String colAlias, int colType) { switch (colType) { case Types.BLOB: case Types.CLOB: return String.format("datalength(%s) != 0", colAlias); }/* w w w .j ava2 s .co m*/ return super.getIsNotNullSQL(colAlias, colType); }
From source file:org.apache.empire.db.codegen.CodeGenParser.java
/** * converts a SQL DataType to a EmpireDataType *///from w w w .j a v a2 s . com private DataType getEmpireDataType(int sqlType) { DataType empireType = DataType.UNKNOWN; switch (sqlType) { case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: case Types.BIGINT: empireType = DataType.INTEGER; break; case Types.VARCHAR: empireType = DataType.TEXT; break; case Types.DATE: empireType = DataType.DATE; break; case Types.TIMESTAMP: case Types.TIME: empireType = DataType.DATETIME; break; case Types.CHAR: empireType = DataType.CHAR; break; case Types.DOUBLE: case Types.FLOAT: case Types.REAL: empireType = DataType.FLOAT; break; case Types.DECIMAL: case Types.NUMERIC: empireType = DataType.DECIMAL; break; case Types.BIT: case Types.BOOLEAN: empireType = DataType.BOOL; break; case Types.CLOB: case Types.LONGVARCHAR: empireType = DataType.CLOB; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: empireType = DataType.BLOB; break; default: empireType = DataType.UNKNOWN; log.warn("SQL column type " + sqlType + " not supported."); } log.debug("Mapping date type " + String.valueOf(sqlType) + " to " + empireType); return empireType; }
From source file:org.cloudgraph.rdb.filter.RDBStatementExecutor.java
@Override public List<PropertyPair> executeInsertWithGeneratedKeys(PlasmaType type, StringBuilder sql, Map<String, PropertyPair> values) { List<PropertyPair> resultKeys = new ArrayList<PropertyPair>(); PreparedStatement statement = null; List<InputStream> streams = null; ResultSet generatedKeys = null; try {/* w ww. j av a 2 s. c om*/ if (log.isDebugEnabled()) { log.debug("execute: " + sql.toString()); StringBuilder paramBuf = createParamDebug(values); log.debug("params: " + paramBuf.toString()); } statement = con.prepareStatement(sql.toString(), PreparedStatement.RETURN_GENERATED_KEYS); for (PropertyPair pair : values.values()) { PlasmaProperty valueProp = pair.getProp(); if (pair.getValueProp() != null) valueProp = pair.getValueProp(); int jdbcType = converter.toJDBCDataType(valueProp, pair.getValue()); Object jdbcValue = converter.toJDBCDataValue(valueProp, pair.getValue()); if (jdbcType != Types.BLOB && jdbcType != Types.VARBINARY) { statement.setObject(pair.getColumn(), jdbcValue, jdbcType); } else { byte[] bytes = (byte[]) jdbcValue; long len = bytes.length; ByteArrayInputStream is = new ByteArrayInputStream(bytes); statement.setBinaryStream(pair.getColumn(), is, len); if (streams == null) streams = new ArrayList<InputStream>(); streams.add(is); } } statement.execute(); generatedKeys = statement.getGeneratedKeys(); ResultSetMetaData rsMeta = generatedKeys.getMetaData(); int numcols = rsMeta.getColumnCount(); if (log.isDebugEnabled()) log.debug("returned " + numcols + " keys"); if (generatedKeys.next()) { // FIXME; without metadata describing which properties // are actually a sequence, there is guess work // involved in matching the values returned // automatically from PreparedStatment as they // are anonymous in terms of the column names // making it impossible to match them to a metadata // property. List<Property> pkPropList = type.findProperties(KeyType.primary); if (pkPropList == null || pkPropList.size() == 0) throw new DataAccessException("no pri-key properties found for type '" + type.getName() + "'"); if (pkPropList.size() > 1) throw new DataAccessException("multiple pri-key properties found for type '" + type.getName() + "' - cannot map to generated keys"); PlasmaProperty prop = (PlasmaProperty) pkPropList.get(0); // FIXME: need to find properties per column by physical name // alias // in case where multiple generated pri-keys for (int i = 1; i <= numcols; i++) { String columnName = rsMeta.getColumnName(i); if (log.isDebugEnabled()) log.debug("returned key column '" + columnName + "'"); int columnType = rsMeta.getColumnType(i); Object value = converter.fromJDBCDataType(generatedKeys, i, columnType, prop); PropertyPair pair = new PropertyPair((PlasmaProperty) prop, value); resultKeys.add(pair); } } } catch (Throwable t) { throw new DataAccessException(t); } finally { try { if (statement != null) statement.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } if (streams != null) try { for (InputStream stream : streams) stream.close(); } catch (IOException e) { log.error(e.getMessage(), e); } } return resultKeys; }
From source file:info.raack.appliancelabeler.data.JDBCDatabase.java
public void saveOAuthTokensForUserId(String userId, String email, Map<String, OAuthConsumerToken> tokens) { HashMap<String, OAuthConsumerToken> hashMapForTokens = new HashMap<String, OAuthConsumerToken>(); hashMapForTokens.putAll(tokens);/*from w w w .ja v a 2 s . c om*/ SqlLobValue blob = new SqlLobValue(SerializationUtils.serialize(hashMapForTokens)); if (email != null) { jdbcTemplate.update(saveAccessTokensForUser, new Object[] { userId, email, blob }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.BLOB }); } else { jdbcTemplate.update(saveAccessTokensForUserWithoutEmail, new Object[] { userId, blob }, new int[] { Types.VARCHAR, Types.BLOB }); } }
From source file:org.nuxeo.ecm.core.storage.sql.db.H2Fulltext.java
protected static String asString(Object data, int type) throws SQLException { if (data == null) { return ""; }/* www . j a va 2 s . c o m*/ switch (type) { case Types.BIT: case Types.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 DbException.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 Types.DATALINK: case Types.DISTINCT: throw new SQLException("Unsupported column data type: " + type); default: return ""; } }
From source file:org.apache.openjpa.jdbc.schema.Column.java
/** * Whether this column is a LOB./*from ww w. j av a2 s .c om*/ */ public boolean isLob() { switch (_type) { case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.CLOB: return true; default: return false; } }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Create the equivalent object in Json (no database access) * //ww w.j ava 2s . c om * @return The ObjectNode Json equivalent */ public ObjectNode getJson() { ObjectNode node = JsonHandler.createObjectNode(); node.put(JSON_MODEL, this.getClass().getSimpleName()); for (DbValue value : allFields) { if (value.column.equalsIgnoreCase("UPDATEDINFO")) { continue; } switch (value.type) { case Types.VARCHAR: case Types.LONGVARCHAR: node.put(value.column, (String) value.value); break; case Types.BIT: node.put(value.column, (Boolean) value.value); break; case Types.TINYINT: node.put(value.column, (Byte) value.value); break; case Types.SMALLINT: node.put(value.column, (Short) value.value); break; case Types.INTEGER: node.put(value.column, (Integer) value.value); break; case Types.BIGINT: node.put(value.column, (Long) value.value); break; case Types.REAL: node.put(value.column, (Float) value.value); break; case Types.DOUBLE: node.put(value.column, (Double) value.value); break; case Types.VARBINARY: node.put(value.column, (byte[]) value.value); break; case Types.DATE: node.put(value.column, ((Date) value.value).getTime()); break; case Types.TIMESTAMP: node.put(value.column, ((Timestamp) value.value).getTime()); break; case Types.CLOB: case Types.BLOB: default: node.put(value.column, "Unsupported type=" + value.type); } } return node; }