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


Java Blob.getBytes方法代码示例

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


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

示例1: 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 or if start is less than 1
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method
 * @since JDK 1.2, HSQLDB 1.7.2
 */
public long position(final Blob pattern, long start) throws SQLException {

    final byte[] data = getData();
    final int    dlen = data.length;

    if (start < MIN_POS) {
        throw JDBCUtil.outOfRangeArgument("start: " + start);
    } else if (start > dlen || pattern == null) {
        return -1L;
    }

    // by now, we know start <= Integer.MAX_VALUE;
    final int  startIndex = (int) start - 1;
    final long plen       = pattern.length();

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

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

    if (pattern instanceof JDBCBlob) {
        bytePattern = ((JDBCBlob) pattern).data();
    } else {
        bytePattern = pattern.getBytes(1L, iplen);
    }

    final int result = KMPSearchAlgorithm.search(data, bytePattern,
        KMPSearchAlgorithm.computeTable(bytePattern), startIndex);

    return (result == -1) ? -1
                          : result + 1;
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:53,代码来源:JDBCBlob.java

示例2: 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 or if start is less than 1
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method
 * @since JDK 1.2
 */
public long position(final Blob pattern,
                     final long start) throws SQLException {

    long patternLength;

    if (start < 1) {
        throw JDBCUtil.outOfRangeArgument("start: " + start);
    } else if ((patternLength = (pattern == null) ? 0
                                                  : pattern.length()) == 0 || start
                                                  > length()) {
        return -1L;
    } else if (patternLength > Integer.MAX_VALUE) {
        throw JDBCUtil.outOfRangeArgument("pattern.length(): "
                                      + patternLength);
    }

    byte[] bytePattern;

    if (pattern instanceof JDBCBlob) {
        bytePattern = ((JDBCBlob) pattern).data();
    } else {
        bytePattern = pattern.getBytes(1L, (int) patternLength);
    }

    return position(bytePattern, start);
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:44,代码来源:JDBCBlobFile.java

示例3: testBug2670

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * @throws Exception
 */
public void testBug2670() throws Exception {
    byte[] blobData = new byte[32];

    for (int i = 0; i < blobData.length; i++) {
        blobData[i] = 1;
    }

    createTable("testBug2670", "(blobField LONGBLOB)");

    PreparedStatement pStmt = this.conn.prepareStatement("INSERT INTO testBug2670 (blobField) VALUES (?)");
    pStmt.setBytes(1, blobData);
    pStmt.executeUpdate();

    this.rs = this.stmt.executeQuery("SELECT blobField FROM testBug2670");
    this.rs.next();

    Blob blob = this.rs.getBlob(1);

    //
    // Test mid-point insertion
    //
    blob.setBytes(4, new byte[] { 2, 2, 2, 2 });

    byte[] newBlobData = blob.getBytes(1L, (int) blob.length());

    assertTrue("Blob changed length", blob.length() == blobData.length);

    assertTrue("New data inserted wrongly", ((newBlobData[3] == 2) && (newBlobData[4] == 2) && (newBlobData[5] == 2) && (newBlobData[6] == 2)));

    //
    // Test end-point insertion
    //
    blob.setBytes(32, new byte[] { 2, 2, 2, 2 });

    assertTrue("Blob length should be 3 larger", blob.length() == (blobData.length + 3));
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:40,代码来源:BlobRegressionTest.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: getBigData

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * 用于查询记录中大数据类型值,若有多条记录符合要求则返回第一条记录的大数据
 *
 * @param sql 查询SQL语句,查询字段的类型必须为Blob类型
 * @param arg 传入的占位符的参数
 * @return 返回查询的大数据,封装在Map中,若没有符合条件的记录则返回空Map
 */
public static Map<String, byte[]> getBigData(String sql, Object... arg) {
    Map<String, byte[]> bigDataMap = new HashMap<String, byte[]>();
    Connection connection = JDBCUtils.getConnection();
    PreparedStatement ps = null;
    ResultSet result = null;

    // 填充占位符
    try {
        ps = connection.prepareStatement(sql);
        for (int i = 0; i < arg.length; i++) {
            ps.setObject(i + 1, arg[i]);
        }

        // 执行SQL语句
        result = ps.executeQuery();
        // 获取字段名
        List<String> columnList = DBUtils.getColumnLabels(result);
        // 遍历结果集
        while (result.next()) {
            // 遍历字段名获取相应大数据值
            for (String column : columnList) {
                Blob data = result.getBlob(column);
                byte[] datas = data.getBytes(1, (int) data.length());
                bigDataMap.put(column, datas);
            }
            break;
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        JDBCUtils.release(result, ps, connection);
    }

    return bigDataMap;
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:44,代码来源:DBUtils.java

示例6: getNullableResult

import java.sql.Blob; //导入方法依赖的package包/类
@Override    
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {    
    Blob blob = cs.getBlob(columnIndex);    
    byte[] returnValue = null;    
    if (null != blob) {    
        returnValue = blob.getBytes(1, (int) blob.length());    
    }    
    try {    
        return new String(returnValue, DEFAULT_CHARSET);    
    } catch (UnsupportedEncodingException e) {    
        throw new RuntimeException("Blob Encoding Error!");    
    }    
}
 
开发者ID:lemon-china,项目名称:lemon-mybatis-plus,代码行数:14,代码来源:BlobTypeHandler.java

示例7: getBlobAsBytes

import java.sql.Blob; //导入方法依赖的package包/类
@Override
public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException {
	logger.debug("Returning Oracle BLOB as bytes");
	Blob blob = rs.getBlob(columnIndex);
	initializeResourcesBeforeRead(rs.getStatement().getConnection(), blob);
	byte[] retVal = (blob != null ? blob.getBytes(1, (int) blob.length()) : null);
	releaseResourcesAfterRead(rs.getStatement().getConnection(), blob);
	return retVal;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:OracleLobHandler.java

示例8: get

import java.sql.Blob; //导入方法依赖的package包/类
protected Object get(ResultSet rs, String name) throws SQLException {
	Blob blob = rs.getBlob( name );
	if ( rs.wasNull() ) return null;
	int length = (int) blob.length();
	byte[] primaryResult = blob.getBytes( 1, length );
	return wrap( primaryResult );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ByteArrayBlobType.java

示例9: setResultToXCO

import java.sql.Blob; //导入方法依赖的package包/类
@Override
public void setResultToXCO(ResultSet rs, String columnName, String property, XCO xco) throws SQLException {
	Blob blob = rs.getBlob(columnName);
	if (blob != null && !rs.wasNull()) {
		byte[] v = blob.getBytes(1, (int) blob.length());
		if (null != v) {
			xco.setByteArrayValue(property, v);
		}
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:11,代码来源:BlobTypeHandler.java

示例10: toEvent

import java.sql.Blob; //导入方法依赖的package包/类
private Event toEvent ( final ResultSet resultSet ) throws SQLException, IOException, ClassNotFoundException
{
    byte[] data;
    switch ( this.jdbcDao.dataFormat )
    {
        case JSON:
            return EventConverter.INSTANCE.toEvent ( resultSet.getString ( 4 ) );
        case BLOB:
            final Blob blob = resultSet.getBlob ( 4 );
            data = blob.getBytes ( 0, Long.valueOf ( blob.length () ).intValue () );
            blob.free ();
            break;
        case BYTES:
            //$FALL-THROUGH$
        default:
            data = resultSet.getBytes ( 4 );
            break;
    }

    logger.trace ( "Deserialize event" );

    final BundleObjectInputStream stream = new BundleObjectInputStream ( new ByteArrayInputStream ( data ), Activator.getContext ().getBundle () );
    try
    {
        final Object o = stream.readObject ();
        if ( o instanceof Event )
        {
            return (Event)o;
        }
        else if ( o == null )
        {
            logger.warn ( "Found null event" );
            return null;
        }
        else
        {
            logger.warn ( "Expected event type {} but found {}. Discarding...", Event.class, o.getClass () );
            return null;
        }
    }
    finally
    {
        stream.close ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:46,代码来源:EventInjector.java

示例11: 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

示例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 or if start is less than 1
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method
 * @since JDK 1.2, HSQLDB 1.7.2
 */
public long position(final Blob pattern, long start) throws SQLException {

    final byte[] ldata = data;

    checkValid(ldata);

    final int dlen = ldata.length;

    if (start < MIN_POS) {
        throw Util.outOfRangeArgument("start: " + start);
    } else if (start > dlen || pattern == null) {
        return -1L;
    } else {
        start--;
    }

    final long plen = pattern.length();

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

    // 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(1L, 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 -1L;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:74,代码来源:JDBCBlob.java

示例13: getAppObject

import java.sql.Blob; //导入方法依赖的package包/类
/** Gets a parameter from the ResultSet.
 * @return the parameter.
 * @param engineType The engine type as defined in init.xml
 * @param rs The ResultSet.
 * @param columnName The name of the parameter.
 * @throws SQLException if a database access error occurs.
 * @throws IOException if any error occurs in reading the data from the database.
 */
public Object getAppObject(ResultSet rs, String columnName, String engineType) throws SQLException, IOException {
    Blob blob = rs.getBlob(columnName);
    if (blob != null)
        return blob.getBytes(1, (int) blob.length());
    else
        return null;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:16,代码来源:TypeDefs.java


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