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.ode.scheduler.simple.JdbcDelegate.java
public boolean insertJob(Job job, String nodeId, boolean loaded) throws DatabaseException { if (__log.isDebugEnabled()) __log.debug("insertJob " + job.jobId + " on node " + nodeId + " loaded=" + loaded); Connection con = null;/*from w w w.j a va 2 s . c o m*/ PreparedStatement ps = null; try { int i = 1; con = getConnection(); ps = con.prepareStatement(SAVE_JOB); ps.setString(i++, job.jobId); ps.setString(i++, nodeId); ps.setLong(i++, job.schedDate); ps.setInt(i++, asInteger(loaded)); ps.setInt(i++, asInteger(job.transacted)); JobDetails details = job.detail; ps.setObject(i++, details.instanceId, Types.BIGINT); ps.setObject(i++, details.mexId, Types.VARCHAR); ps.setObject(i++, details.processId, Types.VARCHAR); ps.setObject(i++, details.type, Types.VARCHAR); ps.setObject(i++, details.channel, Types.VARCHAR); ps.setObject(i++, details.correlatorId, Types.VARCHAR); ps.setObject(i++, details.correlationKeySet, Types.VARCHAR); ps.setObject(i++, details.retryCount, Types.INTEGER); ps.setObject(i++, details.inMem, Types.INTEGER); if (details.detailsExt == null || details.detailsExt.size() == 0) { ps.setObject(i++, null, Types.BLOB); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { StreamUtils.write(bos, (Serializable) details.detailsExt); } catch (Exception ex) { __log.error("Error serializing job detail: " + job.detail); throw new DatabaseException(ex); } ps.setBytes(i++, bos.toByteArray()); } return ps.executeUpdate() == 1; } catch (SQLException se) { throw new DatabaseException(se); } finally { close(ps); close(con); } }
From source file:org.apache.syncope.core.persistence.jpa.content.XMLContentExporter.java
private String getValues(final ResultSet rs, final String columnName, final Integer columnType) throws SQLException { String res = null;/*w ww . j av a2 s. com*/ try { switch (columnType) { case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: final InputStream is = rs.getBinaryStream(columnName); if (is != null) { res = DatatypeConverter.printHexBinary(IOUtils.toByteArray(is)); } break; case Types.BLOB: final Blob blob = rs.getBlob(columnName); if (blob != null) { res = DatatypeConverter.printHexBinary(IOUtils.toByteArray(blob.getBinaryStream())); } break; case Types.BIT: case Types.BOOLEAN: if (rs.getBoolean(columnName)) { res = "1"; } else { res = "0"; } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: final Timestamp timestamp = rs.getTimestamp(columnName); if (timestamp != null) { res = FormatUtils.format(new Date(timestamp.getTime())); } break; default: res = rs.getString(columnName); } } catch (IOException e) { LOG.error("Error retrieving hexadecimal string", e); } return res; }
From source file:org.apache.ode.scheduler.simple.jdbc.SchedulerDAOConnectionImpl.java
public boolean insertJob(JobDAO job, String nodeId, boolean loaded) throws DatabaseException { if (__log.isDebugEnabled()) __log.debug("insertJob " + job.getJobId() + " on node " + nodeId + " loaded=" + loaded); Connection con = null;/*from ww w . j av a 2 s. c om*/ PreparedStatement ps = null; try { int i = 1; con = getConnection(); ps = con.prepareStatement(SAVE_JOB); ps.setString(i++, job.getJobId()); ps.setString(i++, nodeId); ps.setLong(i++, job.getScheduledDate()); ps.setBoolean(i++, loaded); ps.setBoolean(i++, job.isTransacted()); JobDetails details = job.getDetails(); ps.setObject(i++, details.instanceId, Types.BIGINT); ps.setObject(i++, details.mexId, Types.VARCHAR); ps.setObject(i++, details.processId, Types.VARCHAR); ps.setObject(i++, details.type, Types.VARCHAR); ps.setObject(i++, details.channel, Types.VARCHAR); ps.setObject(i++, details.correlatorId, Types.VARCHAR); ps.setObject(i++, details.correlationKeySet, Types.VARCHAR); ps.setObject(i++, details.retryCount, Types.INTEGER); ps.setObject(i++, details.inMem, Types.BOOLEAN); if (details.detailsExt == null || details.detailsExt.size() == 0) { ps.setObject(i++, null, Types.BLOB); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { StreamUtils.write(bos, (Serializable) details.detailsExt); } catch (Exception ex) { __log.error("Error serializing job detail: " + job.getDetails()); throw new DatabaseException(ex); } ps.setObject(i++, bos.toByteArray(), Types.BLOB); } return ps.executeUpdate() == 1; } catch (SQLException se) { throw new DatabaseException(se); } finally { close(ps); close(con); } }
From source file:com.cnd.greencube.server.dao.jdbc.JdbcDAO.java
@SuppressWarnings("rawtypes") private Object getColumnValue(ResultSet rs, ResultSetMetaData meta, int index, Class clazz) throws Exception { Object value = null;/*from ww w .j av a 2 s . co m*/ int type = meta.getColumnType(index); if (clazz == String.class) { value = rs.getString(index); } else if (clazz == Integer.class) { value = rs.getInt(index); } else if (clazz == Boolean.class) { value = rs.getBoolean(index); } else if (clazz == byte[].class) { if (type == Types.BLOB) value = rs.getBlob(index); else value = rs.getBytes(index); } else if (clazz == Long.class) { value = rs.getLong(index); } else if (clazz == BigInteger.class) { value = rs.getBigDecimal(index); } else if (clazz == Float.class) { value = rs.getFloat(index); } else if (clazz == Double.class) { value = rs.getDouble(index); } else if (clazz == java.util.Date.class) { Timestamp time = rs.getTimestamp(index); if (time == null) value = null; else { value = new java.util.Date(time.getTime()); } } else if (clazz == java.sql.Date.class) { value = rs.getDate(index); } else if (clazz == java.sql.Time.class) { value = rs.getTime(index); } else if (clazz == java.sql.Timestamp.class) { value = rs.getTimestamp(index); } else { throw new Exception("Cannote determin this column type:" + meta.getColumnName(index)); } return value; }
From source file:org.traccar.database.QueryBuilder.java
public QueryBuilder setBlob(String name, byte[] value) throws SQLException { for (int i : indexes(name)) { try {// w w w.ja v a 2 s . c o m if (value == null) { statement.setNull(i, Types.BLOB); } else { statement.setBytes(i, value); } } catch (SQLException error) { statement.close(); connection.close(); throw error; } } return this; }
From source file:madgik.exareme.master.queryProcessor.analyzer.stat.ExternalStat.java
private int computeDiffVals(String tableNamePattern, String colNamePattern, int columnType) throws SQLException { String query = "select count(*) as freq from (select distinct " + colNamePattern + " from " + tableNamePattern + " where " + colNamePattern + " is not null) A"; Statement stmt = con.createStatement(); if (columnType == Types.BLOB) { query = "select count(*) as freq from (select " + colNamePattern + " from " + tableNamePattern + " where " + colNamePattern + " is not null) A"; }//from ww w.j a va 2s . c om log.debug("executing distinct values query:" + query); ResultSet rs = stmt.executeQuery(query); int result = 0; while (rs.next()) { result = rs.getInt("freq"); } rs.close(); stmt.close(); return result; }
From source file:org.apache.ddlutils.platform.sybase.SybasePlatform.java
/** * {@inheritDoc}/*from w w w . jav a 2 s .c o m*/ */ protected void setStatementParameterValue(PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException { if ((typeCode == Types.BLOB) || (typeCode == Types.LONGVARBINARY)) { // jConnect doesn't like the BLOB type, but works without problems with LONGVARBINARY // even when using the Blob class if (value instanceof byte[]) { byte[] data = (byte[]) value; statement.setBinaryStream(sqlIndex, new ByteArrayInputStream(data), data.length); } else { // Sybase doesn't like the BLOB type, but works without problems with LONGVARBINARY // even when using the Blob class super.setStatementParameterValue(statement, sqlIndex, Types.LONGVARBINARY, value); } } else if (typeCode == Types.CLOB) { // Same for CLOB and LONGVARCHAR super.setStatementParameterValue(statement, sqlIndex, Types.LONGVARCHAR, value); } else { super.setStatementParameterValue(statement, sqlIndex, typeCode, value); } }
From source file:CreateNewTable.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;/* w w w . j av a2 s . c om*/ else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:org.apache.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes attrs, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); final Table table = getTable(tableName); for (int i = 0; i < attrs.getLength(); i++) { Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType(); if (colType == null) { LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase()); colType = Types.VARCHAR; }//w w w.j a va2 s . c om switch (colType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: try { query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.REAL: case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BLOB: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { LOG.warn("Error decoding hex string to specify a blob parameter", e); query.setParameter(i + 1, attrs.getValue(i)); } catch (Exception e) { LOG.warn("Error creating a new blob parameter", e); } break; default: query.setParameter(i + 1, attrs.getValue(i)); } } }
From source file:Main.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;//from w ww.j a v a 2s.co m else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }