当前位置: 首页>>代码示例>>Java>>正文


Java CallableStatement.setBinaryStream方法代码示例

本文整理汇总了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();
        }
    }

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:61,代码来源:CallableStatementRegressionTest.java


注:本文中的java.sql.CallableStatement.setBinaryStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。