当前位置: 首页>>代码示例>>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;未经允许,请勿转载。