java.sql.Blob Java Examples
The following examples show how to use
java.sql.Blob.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientPreparedQueryBindings.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void setBlob(int parameterIndex, Blob x) { if (x == null) { setNull(parameterIndex); } else { try { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); bytesOut.write('\''); StringUtils.escapeblockFast(x.getBytes(1, (int) x.length()), bytesOut, (int) x.length(), this.session.getServerSession().useAnsiQuotedIdentifiers()); bytesOut.write('\''); setValue(parameterIndex, bytesOut.toByteArray(), MysqlType.BLOB); } catch (Throwable t) { throw ExceptionFactory.createException(t.getMessage(), t); } } }
Example #2
Source File: StreamBasedWritesTest.java From herddb with Apache License 2.0 | 6 votes |
private static void checkBlob(ResultSet rs, int index, byte[] expected, int key) { try { byte[] actual = rs.getBytes(index); Assert.assertArrayEquals(expected, actual); if (expected != null) { DataInputStream dataInputStream = new DataInputStream(rs.getBinaryStream(index)); byte[] actualFromStream = new byte[actual.length]; dataInputStream.readFully(actualFromStream); Assert.assertArrayEquals("error at key " + key, expected, actualFromStream); Blob blob = rs.getBlob(index); assertEquals("error at key " + key, blob.length(), actual.length); DataInputStream dataInputStream2 = new DataInputStream(blob.getBinaryStream()); byte[] actualFromStream2 = new byte[actual.length]; dataInputStream2.readFully(actualFromStream2); Assert.assertArrayEquals("error at key " + key, expected, actualFromStream2); } byte[] object = (byte[]) rs.getObject(index); Assert.assertArrayEquals((byte[]) expected, object); } catch (SQLException | IOException e) { throw new RuntimeException(e); } }
Example #3
Source File: ProxiedDFSClient.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
@Override public LocatedBlocks getLocatedBlocks(String src, long start, long length) throws IOException { try { try (PreparedStatement statement = connection.prepareStatement("call SYSCS_UTIL.SYSCS_HDFS_OPERATION(?, ?)")) { statement.setString(1, src); statement.setString(2, "blocks"); try (ResultSet rs = statement.executeQuery()) { if (!rs.next()) { throw new IOException("No results for getFileStatus"); } Blob blob = rs.getBlob(1); byte[] bytes = blob.getBytes(1, (int) blob.length()); HdfsProtos.LocatedBlocksProto lbp = HdfsProtos.LocatedBlocksProto.parseFrom(bytes); // TODO return PBHelper.convert(lbp); return null; } } } catch (SQLException e) { throw new IOException(e); } }
Example #4
Source File: EmpEmployeesDMLStmt.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
protected void insertToGFXDTable(Connection conn, int[] eid, String[] emp_name, int[] deptid, Date[] since, String[] addr, Blob[] picture, String[] ssn, int size, List<SQLException> exceptions, boolean isPut) throws SQLException { PreparedStatement stmt = conn.prepareStatement(isPut ? put : insert); int tid = getMyTid(); int count = -1; for (int i=0 ; i<size ; i++) { try { count = insertToTable(stmt, eid[i], emp_name[i], deptid[i], since[i], addr[i], picture[i], ssn[i], tid, isPut); if (count != ((Integer)verifyRowCount.get(tid+"_insert"+i)).intValue()) { Log.getLogWriter().info("Gfxd insert has different row count from that of derby " + "derby inserted " + ((Integer)verifyRowCount.get(tid+"_insert"+i)).intValue() + " but gfxd inserted " + count); } } catch (SQLException se) { SQLHelper.handleGFGFXDException(se, exceptions); } } }
Example #5
Source File: EtDataSourceManager.java From EasyTransaction with Apache License 2.0 | 6 votes |
private List<byte[]> getRollbackInfo(String xid, long branchId, Connection conn, String resourceId) throws SQLException { ResultSet rs = null; PreparedStatement selectPST = null; selectPST = conn.prepareStatement(SELECT_UNDO_LOG_SQL); selectPST.setLong(1, branchId); selectPST.setString(2, xid); rs = selectPST.executeQuery(); List<byte[]> result = new ArrayList<>(); try { while (rs.next()) { Blob b = rs.getBlob("rollback_info"); byte[] rollbackInfo = BlobUtils.blob2Bytes(b); result.add(rollbackInfo); } } finally { rs.close(); } return result; }
Example #6
Source File: JDBCResourceStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private InputStream getInputStream(String resPath, ResultSet rs) throws SQLException, IOException { if (rs == null) { return null; } Blob blob = rs.getBlob(META_TABLE_CONTENT); if (blob == null || blob.length() == 0) { return openPushdown(resPath); // empty bytes is pushdown indicator } else { return blob.getBinaryStream(); } }
Example #7
Source File: DefaultLobHandler.java From java-technology-stack with MIT License | 5 votes |
@Override public void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content) throws SQLException { if (streamAsLob) { if (content != null) { ps.setBlob(paramIndex, new ByteArrayInputStream(content), content.length); } else { ps.setBlob(paramIndex, (Blob) null); } } else if (wrapAsLob) { if (content != null) { ps.setBlob(paramIndex, new PassThroughBlob(content)); } else { ps.setBlob(paramIndex, (Blob) null); } } else { ps.setBytes(paramIndex, content); } if (logger.isDebugEnabled()) { logger.debug(content != null ? "Set bytes for BLOB with length " + content.length : "Set BLOB to null"); } }
Example #8
Source File: PostgreSQLServerHelper.java From dbtransfer with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void setPreparedValue(PreparedStatement pStm, int col, Object o, int type ) throws SQLException { if( type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.VARBINARY || type == Types.BINARY ) { if( o != null ) { o = outputValue( o ); // System.out.println( "BLOB class: " + o.getClass() + " Type: " + type + " Col: " + col ); if( o instanceof byte[] ) { pStm.setBytes( col + 1, ( byte[] )o ); } else { Blob b = ( Blob )o; pStm.setBytes( col + 1, b.getBytes( 1, ( int )b.length() ) ); } } else { pStm.setBytes( col + 1, null ); } } else { super.setPreparedValue( pStm, col, o, type ); } }
Example #9
Source File: JdbcUtils.java From spring-analysis-note with MIT License | 5 votes |
/** * Retrieve a JDBC column value from a ResultSet, using the most appropriate * value type. The returned value should be a detached value object, not having * any ties to the active ResultSet: in particular, it should not be a Blob or * Clob object but rather a byte array or String representation, respectively. * <p>Uses the {@code getObject(index)} method, but includes additional "hacks" * to get around Oracle 10g returning a non-standard object for its TIMESTAMP * datatype and a {@code java.sql.Date} for DATE columns leaving out the * time portion: These columns will explicitly be extracted as standard * {@code java.sql.Timestamp} object. * @param rs is the ResultSet holding the data * @param index is the column index * @return the value object * @throws SQLException if thrown by the JDBC API * @see java.sql.Blob * @see java.sql.Clob * @see java.sql.Timestamp */ @Nullable public static Object getResultSetValue(ResultSet rs, int index) throws SQLException { Object obj = rs.getObject(index); String className = null; if (obj != null) { className = obj.getClass().getName(); } if (obj instanceof Blob) { Blob blob = (Blob) obj; obj = blob.getBytes(1, (int) blob.length()); } else if (obj instanceof Clob) { Clob clob = (Clob) obj; obj = clob.getSubString(1, (int) clob.length()); } else if ("oracle.sql.TIMESTAMP".equals(className) || "oracle.sql.TIMESTAMPTZ".equals(className)) { obj = rs.getTimestamp(index); } else if (className != null && className.startsWith("oracle.sql.DATE")) { String metaDataClassName = rs.getMetaData().getColumnClassName(index); if ("java.sql.Timestamp".equals(metaDataClassName) || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) { obj = rs.getTimestamp(index); } else { obj = rs.getDate(index); } } else if (obj instanceof java.sql.Date) { if ("java.sql.Timestamp".equals(rs.getMetaData().getColumnClassName(index))) { obj = rs.getTimestamp(index); } } return obj; }
Example #10
Source File: JdbcTypeJavaClassMappings.java From lams with GNU General Public License v2.0 | 5 votes |
private static ConcurrentHashMap<Class, Integer> buildJavaClassToJdbcTypeCodeMappings() { final ConcurrentHashMap<Class, Integer> workMap = new ConcurrentHashMap<>(); // these mappings are the ones outlined specifically in the spec workMap.put( String.class, Types.VARCHAR ); workMap.put( BigDecimal.class, Types.NUMERIC ); workMap.put( BigInteger.class, Types.NUMERIC ); workMap.put( Boolean.class, Types.BIT ); workMap.put( Short.class, Types.SMALLINT ); workMap.put( Integer.class, Types.INTEGER ); workMap.put( Long.class, Types.BIGINT ); workMap.put( Float.class, Types.REAL ); workMap.put( Double.class, Types.DOUBLE ); workMap.put( byte[].class, Types.LONGVARBINARY ); workMap.put( java.sql.Date.class, Types.DATE ); workMap.put( Time.class, Types.TIME ); workMap.put( Timestamp.class, Types.TIMESTAMP ); workMap.put( Blob.class, Types.BLOB ); workMap.put( Clob.class, Types.CLOB ); workMap.put( Array.class, Types.ARRAY ); workMap.put( Struct.class, Types.STRUCT ); workMap.put( Ref.class, Types.REF ); workMap.put( Class.class, Types.JAVA_OBJECT ); workMap.put( RowId.class, Types.ROWID ); workMap.put( SQLXML.class, Types.SQLXML ); // additional "common sense" registrations workMap.put( Character.class, Types.CHAR ); workMap.put( char[].class, Types.VARCHAR ); workMap.put( Character[].class, Types.VARCHAR ); workMap.put( Byte[].class, Types.LONGVARBINARY ); workMap.put( java.util.Date.class, Types.TIMESTAMP ); workMap.put( Calendar.class, Types.TIMESTAMP ); return workMap; }
Example #11
Source File: CallableStatement40.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
public <T> T getObject( int parameterIndex, Class<T> type ) throws SQLException { // checkForClosedStatement() should be called by all of the // more specific methods to which we forward this call if ( type == null ) { throw mismatchException( "NULL", parameterIndex ); } Object retval; if ( String.class.equals( type ) ) { retval = getString( parameterIndex ); } else if ( BigDecimal.class.equals( type ) ) { retval = getBigDecimal( parameterIndex ); } else if ( Boolean.class.equals( type ) ) { retval = Boolean.valueOf( getBoolean(parameterIndex ) ); } else if ( Byte.class.equals( type ) ) { retval = Byte.valueOf( getByte( parameterIndex ) ); } else if ( Short.class.equals( type ) ) { retval = Short.valueOf( getShort( parameterIndex ) ); } else if ( Integer.class.equals( type ) ) { retval = Integer.valueOf( getInt( parameterIndex ) ); } else if ( Long.class.equals( type ) ) { retval = Long.valueOf( getLong( parameterIndex ) ); } else if ( Float.class.equals( type ) ) { retval = Float.valueOf( getFloat( parameterIndex ) ); } else if ( Double.class.equals( type ) ) { retval = Double.valueOf( getDouble( parameterIndex ) ); } else if ( Date.class.equals( type ) ) { retval = getDate( parameterIndex ); } else if ( Time.class.equals( type ) ) { retval = getTime( parameterIndex ); } else if ( Timestamp.class.equals( type ) ) { retval = getTimestamp( parameterIndex ); } else if ( Blob.class.equals( type ) ) { retval = getBlob( parameterIndex ); } else if ( Clob.class.equals( type ) ) { retval = getClob( parameterIndex ); } else if ( type.isArray() && type.getComponentType().equals( byte.class ) ) { retval = getBytes( parameterIndex ); } else { retval = getObject( parameterIndex ); } if ( wasNull() ) { retval = null; } if ( (retval == null) || (type.isInstance( retval )) ) { return type.cast( retval ); } throw mismatchException( type.getName(), parameterIndex ); }
Example #12
Source File: PooledConnection.java From FHIR with Apache License 2.0 | 5 votes |
@Override public Blob createBlob() throws SQLException { try { return wrapped.createBlob(); } catch (SQLException x) { this.reusable = !pool.checkConnectionFailure(x); throw x; } }
Example #13
Source File: CrossConverters.java From vertx-sql-client with Apache License 2.0 | 5 votes |
static final Object setObject(int targetType, Blob source) { switch (targetType) { case ClientTypes.BLOB: return source; default: throw new IllegalArgumentException("SQLState.LANG_DATA_TYPE_SET_MISMATCH java.sql.Blob" + ClientTypes.getTypeString(targetType)); } }
Example #14
Source File: DDMMMYYImportOra.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public Blob getBlob(int columnIndex) throws SQLException { if (this.lobsInExtFile) { return super.getBlob(columnIndex); } else { // data is in the main export file, stored in hex format. String hexData = getCurrentRow()[columnIndex - 1]; byte[] data = null; if (hexData != null) { data = fromHexString(hexData, 0, hexData.length()); // fromHexString() returns null if the hex string // is invalid one. It is invalid if the data string // length is not multiple of 2 or the data string // contains non-hex characters. if (data != null) { this.wasNull = false; return new ImportBlob(data); } else { throw new SQLException( "An invalid hexadecimal string '" + hexData + "' detected in the import file at line " + getCurrentLineNumber() + " column " + columnIndex, "XIE0N", 20000); } } else { this.wasNull = true; return null; } } }
Example #15
Source File: DelegatingResultSet.java From commons-dbcp with Apache License 2.0 | 5 votes |
@Override public Blob getBlob(final String colName) throws SQLException { try { return resultSet.getBlob(colName); } catch (final SQLException e) { handleException(e); return null; } }
Example #16
Source File: ResourceRegistryStandardImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void release(Blob blob) { if ( blobs == null ) { log.debug( "Request to release Blob, but appears no Blobs have ever been registered" ); return; } blobs.remove( blob ); }
Example #17
Source File: ShardResultSet.java From Zebra with Apache License 2.0 | 4 votes |
@Override public Blob getBlob(String columnLabel) throws SQLException { checkClosed(); return super.getBlob(columnLabel); }
Example #18
Source File: ResultSetImpl.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Blob getBlob(int columnIndex) throws SQLException { throw new UnsupportedOperationException(); }
Example #19
Source File: BasicScalarSuppliers.java From doma with Apache License 2.0 | 4 votes |
public static Supplier<Scalar<Blob, Blob>> ofBlob() { return () -> new BasicScalar<>(new BlobWrapper()); }
Example #20
Source File: ResultSetStub.java From development with Apache License 2.0 | 4 votes |
@Override public Blob getBlob(String colName) throws SQLException { return null; }
Example #21
Source File: MockResultSet.java From tddl with Apache License 2.0 | 4 votes |
public Blob getBlob(int i) throws SQLException { return (Blob) getObject(i); }
Example #22
Source File: ParameterMappingTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void blobIn( Blob c, String[] result ) throws Exception { result[ 0 ] = getBlobValue( c ); }
Example #23
Source File: PrestoResultSetMetaData.java From presto with Apache License 2.0 | 4 votes |
@Override public String getColumnClassName(int column) throws SQLException { // see javax.sql.rowset.RowSetMetaDataImpl switch (column(column).getColumnType()) { case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class.getName(); case Types.BOOLEAN: case Types.BIT: return Boolean.class.getName(); case Types.TINYINT: return Byte.class.getName(); case Types.SMALLINT: return Short.class.getName(); case Types.INTEGER: return Integer.class.getName(); case Types.BIGINT: return Long.class.getName(); case Types.REAL: return Float.class.getName(); case Types.FLOAT: case Types.DOUBLE: return Double.class.getName(); case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return "byte[]"; case Types.DATE: return Date.class.getName(); case Types.TIME: return Time.class.getName(); case Types.TIMESTAMP: return Timestamp.class.getName(); case Types.BLOB: return Blob.class.getName(); case Types.CLOB: return Clob.class.getName(); case Types.ARRAY: return Array.class.getName(); } return String.class.getName(); }
Example #24
Source File: StubSyncResolver.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public void setBlob(String parameterName, Blob x) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); }
Example #25
Source File: EnvironmentEntity.java From kardio with Apache License 2.0 | 4 votes |
/** * @return the marathonJson */ public Blob getMarathonJson() { return marathonJson; }
Example #26
Source File: AvaticaSite.java From calcite-avatica with Apache License 2.0 | 4 votes |
public void setObject(Object x, int targetSqlType) { if (x == null || Types.NULL == targetSqlType) { setNull(targetSqlType); return; } switch (targetSqlType) { case Types.CLOB: case Types.DATALINK: case Types.NCLOB: case Types.OTHER: case Types.REF: case Types.SQLXML: case Types.STRUCT: throw notImplemented(); case Types.ARRAY: setArray(toArray(x)); break; case Types.BIGINT: setLong(toLong(x)); break; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: setBytes(toBytes(x)); break; case Types.BIT: case Types.BOOLEAN: setBoolean(toBoolean(x)); break; case Types.BLOB: if (x instanceof Blob) { setBlob((Blob) x); break; } else if (x instanceof InputStream) { setBlob((InputStream) x); } throw unsupportedCast(x.getClass(), Blob.class); case Types.DATE: setDate(toDate(x), calendar); break; case Types.DECIMAL: case Types.NUMERIC: setBigDecimal(toBigDecimal(x)); break; case Types.DISTINCT: throw notImplemented(); case Types.DOUBLE: case Types.FLOAT: // yes really; SQL FLOAT is up to 8 bytes setDouble(toDouble(x)); break; case Types.INTEGER: setInt(toInt(x)); break; case Types.JAVA_OBJECT: setObject(x); break; case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.VARCHAR: case Types.CHAR: case Types.NCHAR: setString(toString(x)); break; case Types.REAL: setFloat(toFloat(x)); break; case Types.ROWID: if (x instanceof RowId) { setRowId((RowId) x); break; } throw unsupportedCast(x.getClass(), RowId.class); case Types.SMALLINT: setShort(toShort(x)); break; case Types.TIME: setTime(toTime(x), calendar); break; case Types.TIMESTAMP: setTimestamp(toTimestamp(x), calendar); break; case Types.TINYINT: setByte(toByte(x)); break; default: throw notImplemented(); } }
Example #27
Source File: LobStreamsTest.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** * Tests the BlobOutputStream.write(byte b[], int off, int len) method **/ public void testBlobWrite3Param() throws Exception { InputStream streamIn = new LoopingAlphabetStream(streamSize[0]); assertTrue("FAIL -- file not found", streamIn != null); PreparedStatement stmt3 = prepareStatement( "SELECT b FROM testBlobX1 WHERE a = 1"); ResultSet rs3 = stmt3.executeQuery(); rs3.next(); Blob blob = rs3.getBlob(1); assertTrue ("FAIL -- blob is NULL", (blob != null)); int count = 0; byte[] buffer = new byte[1024]; OutputStream outstream = blob.setBinaryStream(1L); while ((count = streamIn.read(buffer)) != -1) { outstream.write(buffer, 0, count); } outstream.close(); streamIn.close(); PreparedStatement stmt4 = prepareStatement( "UPDATE testBlobX1 SET b = ? WHERE a = 1"); stmt4.setBlob(1, blob); stmt4.executeUpdate(); stmt4.close(); rs3.close(); rs3 = stmt3.executeQuery(); assertTrue("FAIL -- blob not found", rs3.next()); blob = rs3.getBlob(1); long new_length = blob.length(); assertEquals("FAIL -- wrong blob length;", streamSize[0], new_length); // Check contents ... InputStream fStream = new LoopingAlphabetStream(streamSize[0]); InputStream lStream = blob.getBinaryStream(); assertTrue("FAIL - Blob and file contents do not match", compareLob2File(fStream, lStream)); fStream.close(); lStream.close(); rs3.close(); stmt3.close(); }
Example #28
Source File: StubWebRowSetImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public void updateBlob(int columnIndex, Blob x) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); }
Example #29
Source File: StubJdbcRowSetImpl.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Override public void updateBlob(String columnLabel, Blob x) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); }
Example #30
Source File: JdbcResultSet.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void updateBlob(int colIdx, Blob x) throws SQLException { throw new SQLFeatureNotSupportedException("Updates are not supported."); }