当前位置: 首页>>代码示例>>Java>>正文


Java Blob类代码示例

本文整理汇总了Java中java.sql.Blob的典型用法代码示例。如果您正苦于以下问题:Java Blob类的具体用法?Java Blob怎么用?Java Blob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Blob类属于java.sql包,在下文中一共展示了Blob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exportBackup

import java.sql.Blob; //导入依赖的package包/类
public void exportBackup(int id, OutputStream out) {
	Connection conn = null;
	PreparedStatement pstmt = null;
	try {
		conn = DBPower.getConnection(table.getId());
		conn.setAutoCommit(false);
		pstmt = conn.prepareStatement(SELECT_CONTENT_SQL);
		pstmt.setInt(1, id);
		ResultSet rs = pstmt.executeQuery();
		if (rs.next()) {
			Blob blob = rs.getBlob(1);
			InputStream in = blob.getBinaryStream();
			byte[] buf = new byte[1024];
			int len = 0;
			while ((len = in.read(buf)) != -1) {
				out.write(buf, 0, len);
			}
			in.close();
		}
		conn.commit();
	} catch (Exception e) {
		log.error( "", e );
	} finally {
		DBUtil.close(pstmt, conn);
	}
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:27,代码来源:BackupManagerImpl.java

示例2: unwrap

import java.sql.Blob; //导入依赖的package包/类
@Override
@SuppressWarnings( {"unchecked" } )
public <X> X unwrap(byte[] value, Class<X> type, WrapperOptions options) {
	if ( value == null ) {
		return null;
	}
	if ( Byte[].class.isAssignableFrom( type ) ) {
		return (X) value;
	}
	if ( byte[].class.isAssignableFrom( type ) ) {
		return (X) value;
	}
	if ( InputStream.class.isAssignableFrom( type ) ) {
		return (X) new ByteArrayInputStream( value );
	}
	if ( BinaryStream.class.isAssignableFrom( type ) ) {
		return (X) new BinaryStreamImpl( value );
	}
	if ( Blob.class.isAssignableFrom( type ) ) {
		return (X) options.getLobCreator().createBlob( value );
	}

	throw unknownUnwrap( type );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:25,代码来源:Base64ByteArrayTypeDescriptor.java

示例3: wrap

import java.sql.Blob; //导入依赖的package包/类
@Override
public <X> byte[] wrap(X value, WrapperOptions options) {
	if ( value == null ) {
		return null;
	}
	if ( Byte[].class.isInstance( value ) ) {
		return unwrapBytes( (Byte[]) value );
	}
	if ( byte[].class.isInstance( value ) ) {
		return (byte[]) value;
	}
	if ( InputStream.class.isInstance( value ) ) {
		return DataHelper.extractBytes( (InputStream) value );
	}
	if ( Blob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
		try {
			return DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() );
		}
		catch (SQLException e) {
			throw new HibernateException( "Unable to access lob stream", e );
		}
	}

	throw unknownWrap( value.getClass() );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:26,代码来源:Base64ByteArrayTypeDescriptor.java

示例4: getNullableResult

import java.sql.Blob; //导入依赖的package包/类
@Override
public byte[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
	Blob blob = rs.getBlob(columnIndex);
	byte[] returnValue = null;
	if (null != blob) {
		returnValue = blob.getBytes(1, (int) blob.length());
	}
	return returnValue;
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:10,代码来源:BlobTypeHandler.java

示例5: setAppObject

import java.sql.Blob; //导入依赖的package包/类
/** Sets a parameter in the PreparedStatement.
 * @param engineType The engine type as defined in init.xml
 * @param pstmt The PreparedStatement.
 * @param parameterIndex The index of the parameter that is to be set.
 * @param value The object to be assigned to the parameter.
 * @throws SQLException if a database access error occurs.
 */
public void setAppObject(PreparedStatement pstmt, int parameterIndex, Object value, String engineType)
throws SQLException {
    if (value != null) {
        if (!(value instanceof byte[]))
            value = DataTypeMapper.instance().map(value, byte[].class);
        if ("oracle".equalsIgnoreCase(engineType) && !supportsStdLob(pstmt)) {
            Blob blob = createBlob(pstmt.getConnection(), (byte[]) value);
            pstmt.setBlob(parameterIndex, blob);
        } else {
            byte[] bytes = (byte[]) value;
            InputStream stream = new BufferedInputStream(new ByteArrayInputStream(bytes));
            pstmt.setBinaryStream(parameterIndex, stream, bytes.length);
        }
    } else
        pstmt.setNull(parameterIndex, getSqlType(Defaults.BLOB, engineType));
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:24,代码来源:TypeDefs.java

示例6: convertColumnValue

import java.sql.Blob; //导入依赖的package包/类
Object convertColumnValue(Object value, int column, int type) {

        if (value == null) {
            return value;
        }

        try {
            if (value instanceof Clob) {
                return ((Clob) value).getSubString(
                    1, (int) ((Clob) value).length());
            } else if (value instanceof Blob) {
                return ((Blob) value).getBytes(
                    1, (int) ((Blob) value).length());
            }
        } catch (SQLException e) {
            return null;
        }

        return (value);
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:21,代码来源:TransferHelper.java

示例7: buildJdbcJavaClassMappings

import java.sql.Blob; //导入依赖的package包/类
private static ConcurrentHashMap<Class, Integer> buildJdbcJavaClassMappings() {
	ConcurrentHashMap<Class, Integer> jdbcJavaClassMappings = new ConcurrentHashMap<Class, Integer>();

	// these mappings are the ones outlined specifically in the spec
	jdbcJavaClassMappings.put( String.class, Types.VARCHAR );
	jdbcJavaClassMappings.put( BigDecimal.class, Types.NUMERIC );
	jdbcJavaClassMappings.put( Boolean.class, Types.BIT );
	jdbcJavaClassMappings.put( Integer.class, Types.INTEGER );
	jdbcJavaClassMappings.put( Long.class, Types.BIGINT );
	jdbcJavaClassMappings.put( Float.class, Types.REAL );
	jdbcJavaClassMappings.put( Double.class, Types.DOUBLE );
	jdbcJavaClassMappings.put( byte[].class, Types.LONGVARBINARY );
	jdbcJavaClassMappings.put( java.sql.Date.class, Types.DATE );
	jdbcJavaClassMappings.put( Time.class, Types.TIME );
	jdbcJavaClassMappings.put( Timestamp.class, Types.TIMESTAMP );
	jdbcJavaClassMappings.put( Blob.class, Types.BLOB );
	jdbcJavaClassMappings.put( Clob.class, Types.CLOB );
	jdbcJavaClassMappings.put( Array.class, Types.ARRAY );
	jdbcJavaClassMappings.put( Struct.class, Types.STRUCT );
	jdbcJavaClassMappings.put( Ref.class, Types.REF );
	jdbcJavaClassMappings.put( Class.class, Types.JAVA_OBJECT );

	// additional "common sense" registrations
	jdbcJavaClassMappings.put( Character.class, Types.CHAR );
	jdbcJavaClassMappings.put( char[].class, Types.VARCHAR );
	jdbcJavaClassMappings.put( Character[].class, Types.VARCHAR );
	jdbcJavaClassMappings.put( Byte[].class, Types.LONGVARBINARY );
	jdbcJavaClassMappings.put( java.util.Date.class, Types.TIMESTAMP );
	jdbcJavaClassMappings.put( Calendar.class, Types.TIMESTAMP );

	return jdbcJavaClassMappings;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:JdbcTypeJavaClassMappings.java

示例8: setBlobAsBytes

import java.sql.Blob; //导入依赖的package包/类
@Override
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, final byte[] content)
		throws SQLException {

	if (content != null) {
		Blob blob = (Blob) createLob(ps, false, new LobCallback() {
			@Override
			public void populateLob(Object lob) throws Exception {
				Method methodToInvoke = lob.getClass().getMethod("getBinaryOutputStream");
				OutputStream out = (OutputStream) methodToInvoke.invoke(lob);
				FileCopyUtils.copy(content, out);
			}
		});
		ps.setBlob(paramIndex, blob);
		if (logger.isDebugEnabled()) {
			logger.debug("Set bytes for Oracle BLOB with length " + blob.length());
		}
	}
	else {
		ps.setBlob(paramIndex, (Blob) null);
		logger.debug("Set Oracle BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:OracleLobHandler.java

示例9: getBlob

import java.sql.Blob; //导入依赖的package包/类
public Blob getBlob(int nColNumber) throws TechnicalException
{		
	if(m_resultSet != null)
	{
		try
		{
			Blob blVal = m_resultSet.getBlob(nColNumber);
			return blVal;
		}
		catch (SQLException e)
		{
			forceCloseOnExceptionCatched();
			ProgrammingException.throwException(ProgrammingException.DB_ERROR_RESULT_SET_COL_ACCESS_INT+nColNumber, m_csQuery, e);
		}			
	}
	return null;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:18,代码来源:SQLClause.java

示例10: getObjectFromBlob

import java.sql.Blob; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Caché requires {@code java.sql.Blob} instances to be explicitly freed.
 */
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException {
    Blob blob = rs.getBlob(colName);
    if (blob == null) {
        return null;
    } else {
        try {
            if (blob.length() == 0) {
                return null;
            } else {
                InputStream binaryInput = blob.getBinaryStream();
                if (binaryInput == null) {
                    return null;
                } else if (binaryInput instanceof ByteArrayInputStream && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                    return null;
                } else {
                    ObjectInputStream in = new ObjectInputStream(binaryInput);
                    try {
                        return in.readObject();
                    } finally {
                        in.close();
                    }
                }
            }
        } finally {
            blob.free();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:CacheDelegate.java

示例11: setBlobAsBinaryStream

import java.sql.Blob; //导入依赖的package包/类
@Override
public void setBlobAsBinaryStream(
		PreparedStatement ps, int paramIndex, final InputStream binaryStream, int contentLength)
		throws SQLException {

	if (binaryStream != null) {
		Blob blob = (Blob) createLob(ps, false, new LobCallback() {
			@Override
			public void populateLob(Object lob) throws Exception {
				Method methodToInvoke = lob.getClass().getMethod("getBinaryOutputStream", (Class[]) null);
				OutputStream out = (OutputStream) methodToInvoke.invoke(lob, (Object[]) null);
				FileCopyUtils.copy(binaryStream, out);
			}
		});
		ps.setBlob(paramIndex, blob);
		if (logger.isDebugEnabled()) {
			logger.debug("Set binary stream for Oracle BLOB with length " + blob.length());
		}
	}
	else {
		ps.setBlob(paramIndex, (Blob) null);
		logger.debug("Set Oracle BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:OracleLobHandler.java

示例12: position

import java.sql.Blob; //导入依赖的package包/类
/**
 * Retrieves the byte position in the <code>BLOB</code> value
 * designated by this <code>Blob</code> object at which
 * <code>pattern</code> begins.  The search begins at position
 * <code>start</code>.
 *
 * @param pattern the <code>Blob</code> object designating
 *      the <code>BLOB</code> value for which to search
 * @param start the position in the <code>BLOB</code> value
 *        at which to begin searching; the first position is 1
 * @return the position at which the pattern begins, else -1
 * @exception SQLException if there is an error accessing the
 *        <code>BLOB</code> value
 *
 * @since JDK 1.2, HSQLDB 1.7.2
 */
public long position(final Blob pattern, long start) throws SQLException {

    final byte[] ldata = data;
    final int    dlen  = ldata.length;

    if (start > dlen || pattern == null) {
        return -1;
    } else if (start < 1) {
        start = 0;
    } else {
        start--;
    }

    final long plen = pattern.length();

    if (plen == 0 || start > ((long) dlen) - plen) {
        return -1;
    }

    // by now, we know plen <= Integer.MAX_VALUE
    final int iplen = (int) plen;
    byte[]    bap;

    if (pattern instanceof jdbcBlob) {
        bap = ((jdbcBlob) pattern).data;
    } else {
        bap = pattern.getBytes(1, iplen);
    }

    final int  stop = dlen - iplen;
    final byte b0   = bap[0];

    outer_loop:
    for (int i = (int) start; i <= stop; i++) {
        if (ldata[i] != b0) {
            continue;
        }

        int len     = iplen;
        int doffset = i;
        int poffset = 0;

        while (len-- > 0) {
            if (ldata[doffset++] != bap[poffset++]) {
                continue outer_loop;
            }
        }

        return i + 1;
    }

    return -1;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:70,代码来源:jdbcBlob.java

示例13: testValue

import java.sql.Blob; //导入依赖的package包/类
protected boolean testValue(final Object value) {
    if (value == null) {
        return false;
    }
    final String valueStr;
    if (value instanceof Blob) {
        valueStr = LobHelper.blobToString((Blob) value);
    } else if (value instanceof Clob) {
        valueStr = LobHelper.clobToString((Clob) value);
    } else {
        valueStr = value.toString();
    }
    switch (mode) {
        case LITERAL_FIND:
            if (filterStr == null || filterStr.length() == 0) {
            return true;
        } else {
            return valueStr.toUpperCase().contains(filterStr.toUpperCase());
        }
        case LITERAL_MATCH:
            if (filterStr == null || filterStr.length() == 0) {
            return true;
        } else {
            return filterStr.equals(valueStr);
        }
        case REGEX_FIND:
            return pattern.matcher(valueStr).find();
        case REGEX_MATCH:
            return pattern.matcher(valueStr).matches();
        default:
            throw new RuntimeException(UNKOWN_MODE);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:SuperPatternFilter.java

示例14: useToString

import java.sql.Blob; //导入依赖的package包/类
@Override
protected boolean useToString(int column) {
    Class klass = getModel().getColumnClass(column);
    if (Blob.class.isAssignableFrom(klass)
            || Clob.class.isAssignableFrom(klass)) {
        return false;
    }
    return super.useToString(column);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:StringFallbackRowSorter.java

示例15: getBlob

import java.sql.Blob; //导入依赖的package包/类
public Blob getBlob(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getBlob(parameterName);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:14,代码来源:CallableStatementWrapper.java


注:本文中的java.sql.Blob类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。