當前位置: 首頁>>代碼示例>>Java>>正文


Java Clob.setString方法代碼示例

本文整理匯總了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");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:TemporaryLobCreator.java

示例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;
}
 
開發者ID:gagoyal01,項目名稱:mongodb-rdbms-sync,代碼行數:21,代碼來源:SqlLiteralFactory.java

示例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()));
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:42,代碼來源:BlobRegressionTest.java

示例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 );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:ContextualLobCreator.java

示例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"));
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:47,代碼來源:ResultSetRegressionTest.java

示例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();
            }

        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:54,代碼來源:StringRegressionTest.java


注:本文中的java.sql.Clob.setString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。