當前位置: 首頁>>代碼示例>>Java>>正文


Java Blob.setBytes方法代碼示例

本文整理匯總了Java中java.sql.Blob.setBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java Blob.setBytes方法的具體用法?Java Blob.setBytes怎麽用?Java Blob.setBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Blob的用法示例。


在下文中一共展示了Blob.setBytes方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:40,代碼來源:BlobRegressionTest.java

示例2: getLobLiteral

import java.sql.Blob; //導入方法依賴的package包/類
public static Literal getLobLiteral(Object inputValue, String dataType, Connection connection) throws SQLException{
	Literal literal = null;
	if(connection==null){
		literal = new NullLiteral();
	}else{
		if(SqlColumnType.BLOB.equalsIgnoreCase(dataType)){
			literal= new BlobLiteral();
			Blob blob = connection.createBlob();
			Binary objArray = (Binary) inputValue;
			blob.setBytes(1, objArray.getData());
			literal.setLiteralValue(blob);
		}else if(SqlColumnType.CLOB.equalsIgnoreCase(dataType)){
			literal = new ClobLiteral();
			Clob clob = connection.createClob();
			clob.setString(1, String.valueOf(inputValue));
			literal.setLiteralValue(clob);
		}
	}
	return literal;
}
 
開發者ID:gagoyal01,項目名稱:mongodb-rdbms-sync,代碼行數:21,代碼來源:SqlLiteralFactory.java

示例3: setBlobAsBytes

import java.sql.Blob; //導入方法依賴的package包/類
@Override
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content)
		throws SQLException {

	Blob blob = ps.getConnection().createBlob();
	blob.setBytes(1, content);

	this.temporaryBlobs.add(blob);
	ps.setBlob(paramIndex, blob);

	if (logger.isDebugEnabled()) {
		logger.debug(content != null ? "Copied bytes into temporary BLOB with length " + content.length :
				"Set BLOB to null");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:TemporaryLobCreator.java

示例4: createBlob

import java.sql.Blob; //導入方法依賴的package包/類
@Override
public Blob createBlob(byte[] bytes) {
	try {
		final Blob blob = createBlob();
		blob.setBytes( 1, bytes );
		return blob;
	}
	catch ( SQLException e ) {
		throw new JDBCException( "Unable to set BLOB bytes after creation", e );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:ContextualLobCreator.java

示例5: writeToBlob

import java.sql.Blob; //導入方法依賴的package包/類
/**
 * Writes a byte array to a {@link Blob}.
 * 
 * @param bytes
 *            byte array.
 * @param blob
 *            an initialized {@link Blob}.
 * @return the {@link Blob} instance passed as <code>blob</code> argument.
 * @throws SQLException
 */
public static Blob writeToBlob(byte[] bytes, Blob blob, Session session) throws SQLException {
    if (/*blob != null*/ false) { // not supported
        blob.setBytes(0, bytes);
        blob.truncate(bytes.length);
    } else {
        blob = Hibernate.getLobCreator(session).createBlob(bytes);
    }
    return blob;
}
 
開發者ID:oehf,項目名稱:ipf-flow-manager,代碼行數:20,代碼來源:HibernateUtils.java


注:本文中的java.sql.Blob.setBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。