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