本文整理匯總了Java中java.sql.CallableStatement.setBinaryStream方法的典型用法代碼示例。如果您正苦於以下問題:Java CallableStatement.setBinaryStream方法的具體用法?Java CallableStatement.setBinaryStream怎麽用?Java CallableStatement.setBinaryStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.CallableStatement
的用法示例。
在下文中一共展示了CallableStatement.setBinaryStream方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testBug25715
import java.sql.CallableStatement; //導入方法依賴的package包/類
/**
* Tests fix for BUG#25715 - CallableStatements with OUT/INOUT parameters
* that are "binary" have extra 7 bytes (which happens to be the _binary
* introducer!)
*
* @throws Exception
* if the test fails.
*/
public void testBug25715() throws Exception {
if (!serverSupportsStoredProcedures()) {
return; // no stored procs
}
createProcedure("spbug25715", "(INOUT mblob MEDIUMBLOB) BEGIN SELECT 1 FROM DUAL WHERE 1=0;\nEND");
CallableStatement cstmt = null;
try {
cstmt = this.conn.prepareCall("{call spbug25715(?)}");
byte[] buf = new byte[65];
for (int i = 0; i < 65; i++) {
buf[i] = 1;
}
int il = buf.length;
int[] typesToTest = new int[] { Types.BIT, Types.BINARY, Types.BLOB, Types.JAVA_OBJECT, Types.LONGVARBINARY, Types.VARBINARY };
for (int i = 0; i < typesToTest.length; i++) {
cstmt.setBinaryStream("mblob", new ByteArrayInputStream(buf), buf.length);
cstmt.registerOutParameter("mblob", typesToTest[i]);
cstmt.executeUpdate();
InputStream is = cstmt.getBlob("mblob").getBinaryStream();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int bytesRead = 0;
byte[] readBuf = new byte[256];
while ((bytesRead = is.read(readBuf)) != -1) {
bOut.write(readBuf, 0, bytesRead);
}
byte[] fromSelectBuf = bOut.toByteArray();
int ol = fromSelectBuf.length;
assertEquals(il, ol);
}
cstmt.close();
} finally {
if (cstmt != null) {
cstmt.close();
}
}
}