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


Java Clob.truncate方法代码示例

本文整理汇总了Java中java.sql.Clob.truncate方法的典型用法代码示例。如果您正苦于以下问题:Java Clob.truncate方法的具体用法?Java Clob.truncate怎么用?Java Clob.truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Clob的用法示例。


在下文中一共展示了Clob.truncate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClobTruncate

import java.sql.Clob; //导入方法依赖的package包/类
/**
 * Tests for fix to BUG#1130
 * 
 * @throws Exception
 *             if the test fails
 */
public void testClobTruncate() throws Exception {
    createTable("testClobTruncate", "(field1 TEXT)");
    this.stmt.executeUpdate("INSERT INTO testClobTruncate VALUES ('abcdefg')");

    this.rs = this.stmt.executeQuery("SELECT * FROM testClobTruncate");
    this.rs.next();

    Clob clob = this.rs.getClob(1);
    clob.truncate(3);

    Reader reader = clob.getCharacterStream();
    char[] buf = new char[8];
    int charsRead = reader.read(buf);

    String clobAsString = new String(buf, 0, charsRead);

    assertTrue(clobAsString.equals("abc"));
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:25,代码来源:ResultSetRegressionTest.java

示例2: testBug11614

import java.sql.Clob; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#11614 - StringUtils.getBytes() doesn't work when using
 * multibyte character encodings and a length in _characters_ is specified.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug11614() throws Exception {
    if (versionMeetsMinimum(4, 1)) {
        createTable("testBug11614",
                "(`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `text` TEXT NOT NULL," + "PRIMARY KEY(`id`)) CHARACTER SET utf8 COLLATE utf8_general_ci");

        Properties props = new Properties();
        props.setProperty("characterEncoding", "utf8");

        Connection utf8Conn = null;

        try {
            utf8Conn = getConnectionWithProps(props);

            utf8Conn.createStatement().executeUpdate("INSERT INTO testBug11614  (`id`,`text`) values (1,'')");
            this.rs = utf8Conn.createStatement().executeQuery("SELECT `text` FROM testBug11614 WHERE id=1");
            assertTrue(this.rs.next());

            Clob c = this.rs.getClob(1);
            c.truncate(0);
            int blockSize = 8192;
            int sizeToTest = blockSize + 100;

            StringBuilder blockBuf = new StringBuilder(sizeToTest);

            for (int i = 0; i < sizeToTest; i++) {
                blockBuf.append('\u00f6');
            }

            String valueToTest = blockBuf.toString();

            c.setString(1, valueToTest);
            this.pstmt = utf8Conn.prepareStatement("UPDATE testBug11614 SET `text` = ? WHERE id=1");
            this.pstmt.setClob(1, c);
            this.pstmt.executeUpdate();
            this.pstmt.close();

            String fromDatabase = getSingleIndexedValueWithQuery(utf8Conn, 1, "SELECT `text` FROM testBug11614").toString();
            assertEquals(valueToTest, fromDatabase);
        } finally {
            if (utf8Conn != null) {
                utf8Conn.close();
            }

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


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