本文整理汇总了Java中java.sql.Clob.setString方法的典型用法代码示例。如果您正苦于以下问题:Java Clob.setString方法的具体用法?Java Clob.setString怎么用?Java Clob.setString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Clob
的用法示例。
在下文中一共展示了Clob.setString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setClobAsString
import java.sql.Clob; //导入方法依赖的package包/类
@Override
public void setClobAsString(PreparedStatement ps, int paramIndex, String content)
throws SQLException {
Clob clob = ps.getConnection().createClob();
clob.setString(1, content);
this.temporaryClobs.add(clob);
ps.setClob(paramIndex, clob);
if (logger.isDebugEnabled()) {
logger.debug(content != null ? "Copied string into temporary CLOB with length " + content.length() :
"Set CLOB to null");
}
}
示例2: getLobLiteral
import java.sql.Clob; //导入方法依赖的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: testBug20453712
import java.sql.Clob; //导入方法依赖的package包/类
/**
* Tests fix for BUG#20453712 - CLOB.SETSTRING() WITH VALID INPUT RETURNS EXCEPTION
* server-side prepared statements and streaming BINARY data.
*
* @throws Exception
* if the test fails.
*/
public void testBug20453712() throws Exception {
final String s1 = "NewClobData";
this.rs = this.stmt.executeQuery("select 'a'");
this.rs.next();
final Clob c1 = this.rs.getClob(1);
// check with wrong position
assertThrows(SQLException.class, "Starting position can not be < 1", new Callable<Void>() {
public Void call() throws Exception {
c1.setString(0, s1, 7, 4);
return null;
}
});
// check with wrong substring index
assertThrows(SQLException.class, "String index out of range: 12", new Callable<Void>() {
public Void call() throws Exception {
c1.setString(1, s1, 8, 4);
return null;
}
});
// full replace
c1.setString(1, s1, 3, 4);
assertEquals("Clob", c1.getSubString(1L, (int) c1.length()));
// add
c1.setString(5, s1, 7, 4);
assertEquals("ClobData", c1.getSubString(1L, (int) c1.length()));
// replace middle chars
c1.setString(2, s1, 7, 4);
assertEquals("CDataata", c1.getSubString(1L, (int) c1.length()));
}
示例4: createClob
import java.sql.Clob; //导入方法依赖的package包/类
@Override
public Clob createClob(String string) {
try {
final Clob clob = createClob();
clob.setString( 1, string );
return clob;
}
catch ( SQLException e ) {
throw new JDBCException( "Unable to set CLOB string after creation", e );
}
}
示例5: testUpdateClob
import java.sql.Clob; //导入方法依赖的package包/类
/**
* Checks whether or not ResultSet.updateClob() is implemented
*
* @throws Exception
* if the test fails
*/
public void testUpdateClob() throws Exception {
Statement updatableStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
createTable("testUpdateClob", "(intField INT NOT NULL PRIMARY KEY, clobField TEXT)");
this.stmt.executeUpdate("INSERT INTO testUpdateClob VALUES (1, 'foo')");
this.rs = updatableStmt.executeQuery("SELECT intField, clobField FROM testUpdateClob");
this.rs.next();
Clob clob = this.rs.getClob(2);
clob.setString(1, "bar");
this.rs.updateClob(2, clob);
this.rs.updateRow();
this.rs.moveToInsertRow();
clob.setString(1, "baz");
this.rs.updateInt(1, 2);
this.rs.updateClob(2, clob);
this.rs.insertRow();
clob.setString(1, "bat");
this.rs.updateInt(1, 3);
this.rs.updateClob(2, clob);
this.rs.insertRow();
this.rs.close();
this.rs = this.stmt.executeQuery("SELECT intField, clobField FROM testUpdateClob ORDER BY intField");
this.rs.next();
assertTrue((this.rs.getInt(1) == 1) && this.rs.getString(2).equals("bar"));
this.rs.next();
assertTrue((this.rs.getInt(1) == 2) && this.rs.getString(2).equals("baz"));
this.rs.next();
assertTrue((this.rs.getInt(1) == 3) && this.rs.getString(2).equals("bat"));
}
示例6: 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();
}
}
}
}