本文整理匯總了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));
}
示例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;
}
示例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");
}
}
示例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 );
}
}
示例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;
}