當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。