Java Code Examples for java.sql.ResultSet#updateBlob()

The following examples show how to use java.sql.ResultSet#updateBlob() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testUpdateBlobWithStreamLengthlessParameterName()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob("dBlob", is2);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 2
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testUpdateBlobLengthless()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob(1, is2);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 3
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public void testUpdateBlobLengthless()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob(1, is2);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 4
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the updateBlob that accepts a input stream and the length of the IS
 * and the parameter name String.
 *
 * @throws an Exception
 */
public void testUpdateBlobStringParameterNameWithLengthofIS()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob("dBlob", is2, BYTES2.length);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 5
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Tests the updateBlob that accepts a input stream and the length of the IS
 * and the parameter name String.
 *
 * @throws an Exception
 */
public void testUpdateBlobStringParameterNameWithLengthofIS()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob("dBlob", is2, BYTES2.length);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 6
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the updateBlob that accepts a input stream and the length of the IS
 * and the parameter name String.
 *
 * @throws an Exception
 */
public void testUpdateBlobStringParameterNameWithLengthofIS()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob("dBlob", is2, BYTES2.length);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 7
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * tests the updateBlob that accepts a input stream and the length of the IS.
 *
 * @throws an Exception
 */
public void testUpdateBlobWithLengthofIS()
        throws Exception {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream for insertion.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    // Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2, is1);
    ps_sb.executeUpdate();
    ps_sb.close();

    // Update operation
    ResultSet rs1 = fetchUpd("dBlob", key);
    rs1.next();
    rs1.updateBlob(1, is2, BYTES2.length);
    rs1.updateRow();
    rs1.close();

    // Query to see whether the data that has been updated.
    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 8
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This methods tests the ResultSet interface method
 * updateBlob
 *
 * @throws SQLException if some error occurs while calling the method
 */
public void testUpdateBlobStringParameterName()
throws Exception {
    // Life span of Blob objects are limited by the transaction.  Need
    // autocommit off so Blob objects survive execution of next statement.
    getConnection().setAutoCommit(false);

    //Byte array in which the returned bytes from
    //the Database after the update are stored. This
    //array is then checked to determine if it
    //has the same elements of the Byte array used for
    //the update operation

    byte[] bytes_ret = new byte[10];

    //1 Input Stream for insertion
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);

    //2 Input Stream for insertion
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    //Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");

    //first insert
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2,is1,BYTES1.length);
    ps_sb.executeUpdate();

    //second insert
    int key2 = requestKey();
    ps_sb.setInt(1, key2);
    ps_sb.setBinaryStream(2,is2,BYTES2.length);
    ps_sb.executeUpdate();

    ps_sb.close();

    //Update operation
    //use a different ResultSet variable so that the
    //other tests can go on unimpacted
    //we do not have set methods on Clob and Blob implemented
    //So query the first Clob from the database
    //update the second result set with this
    //Clob value

    ResultSet rs1 = fetch("dBlob", key);
    rs1.next();
    Blob blob = rs1.getBlob(1);
    rs1.close();

    rs1 = fetchUpd("dBlob", key2);
    rs1.next();
    rs1.updateBlob("dBlob",blob);
    rs1.updateRow();
    rs1.close();

    //Query to see whether the data that has been updated
    //using the updateBlob method is the same
    //data that we expected

    rs1 = fetch("dBlob", key2);
    rs1.next();
    assertEquals(blob, rs1.getBlob(1)); 
    rs1.close();
}
 
Example 9
Source File: GenericDbmsSupport.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public void updateBlob(ResultSet rs, String column, Object blobUpdateHandle) throws SQLException, JdbcException {
	// updateBlob is not implemented by the WebSphere implementation of ResultSet
	rs.updateBlob(column, (Blob)blobUpdateHandle);
}
 
Example 10
Source File: UnsupportedUpdateOperationResultSetTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnLabelWithInputStreamAndLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob("label", System.in, 100);
    }
}
 
Example 11
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * This methods tests the ResultSet interface method
 * updateBlob
 *
 * @throws SQLException if some error occurs while calling the method
 */
public void testUpdateBlobStringParameterName()
throws Exception {
    // Life span of Blob objects are limited by the transaction.  Need
    // autocommit off so Blob objects survive execution of next statement.
    getConnection().setAutoCommit(false);

    //Byte array in which the returned bytes from
    //the Database after the update are stored. This
    //array is then checked to determine if it
    //has the same elements of the Byte array used for
    //the update operation

    byte[] bytes_ret = new byte[10];

    //1 Input Stream for insertion
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);

    //2 Input Stream for insertion
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    //Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");

    //first insert
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2,is1,BYTES1.length);
    ps_sb.executeUpdate();

    //second insert
    int key2 = requestKey();
    ps_sb.setInt(1, key2);
    ps_sb.setBinaryStream(2,is2,BYTES2.length);
    ps_sb.executeUpdate();

    ps_sb.close();

    //Update operation
    //use a different ResultSet variable so that the
    //other tests can go on unimpacted
    //we do not have set methods on Clob and Blob implemented
    //So query the first Clob from the database
    //update the second result set with this
    //Clob value

    ResultSet rs1 = fetch("dBlob", key);
    rs1.next();
    Blob blob = rs1.getBlob(1);
    rs1.close();

    rs1 = fetchUpd("dBlob", key2);
    rs1.next();
    rs1.updateBlob("dBlob",blob);
    rs1.updateRow();
    rs1.close();

    //Query to see whether the data that has been updated
    //using the updateBlob method is the same
    //data that we expected

    rs1 = fetch("dBlob", key2);
    rs1.next();
    assertEquals(blob, rs1.getBlob(1)); 
    rs1.close();
}
 
Example 12
Source File: UnsupportedUpdateOperationResultSetTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnLabelWithInputStream() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob("label", System.in);
    }
}
 
Example 13
Source File: UnsupportedUpdateOperationResultSetTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnIndexWithInputStream() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob(1, System.in);
    }
}
 
Example 14
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob("label", (Blob) null);
    }
}
 
Example 15
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnIndexWithInputStream() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob(1, System.in);
    }
}
 
Example 16
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This methods tests the ResultSet interface method
 * updateBlob
 *
 * @throws SQLException if some error occurs while calling the method
 */
public void testUpdateBlob()
throws Exception {

    // Life span of Blob objects are limited by the transaction.  Need
    // autocommit off so Blob objects survive execution of next statement.
    getConnection().setAutoCommit(false);

    //Byte array in which the returned bytes from
    //the Database after the update are stored. This
    //array is then checked to determine if it
    //has the same elements of the Byte array used for
    //the update operation

    byte[] bytes_ret = new byte[10];

    //1 Input Stream for insertion
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);

    //2 Input Stream for insertion
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    //Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");

    //first insert
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2,is1,BYTES1.length);
    ps_sb.executeUpdate();

    //second insert
    int key2 = requestKey();
    ps_sb.setInt(1, key2);
    ps_sb.setBinaryStream(2,is2,BYTES2.length);
    ps_sb.executeUpdate();

    ps_sb.close();

    //Update operation
    //use a different ResultSet variable so that the
    //other tests can go on unimpacted
    //we do not have set methods on Clob and Blob implemented
    //So query the first Clob from the database
    //update the second result set with this
    //Clob value

    ResultSet rs1 = fetch("dBlob", key);
    rs1.next();
    Blob blob = rs1.getBlob(1);
    rs1.close();

    rs1 = fetchUpd("dBlob", key2);
    rs1.next();
    rs1.updateBlob(1,blob);
    rs1.updateRow();
    rs1.close();

    //Query to see whether the data that has been updated
    //using the updateBlob method is the same
    //data that we expected

    rs1 = fetch("dBlob", key2);
    rs1.next();
    assertEquals(blob, rs1.getBlob(1));
    rs1.close();
}
 
Example 17
Source File: GenericDbmsSupport.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public void updateBlob(ResultSet rs, int column, Object blobUpdateHandle) throws SQLException, JdbcException {
	// updateBlob is not implemented by the WebSphere implementation of ResultSet
	rs.updateBlob(column, (Blob)blobUpdateHandle);
}
 
Example 18
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnLabelWithInputStreamAndLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob("label", System.in, 100);
    }
}
 
Example 19
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * This methods tests the ResultSet interface method
 * updateBlob
 *
 * @throws SQLException if some error occurs while calling the method
 */
public void testUpdateBlob()
throws Exception {

    // Life span of Blob objects are limited by the transaction.  Need
    // autocommit off so Blob objects survive execution of next statement.
    getConnection().setAutoCommit(false);

    //Byte array in which the returned bytes from
    //the Database after the update are stored. This
    //array is then checked to determine if it
    //has the same elements of the Byte array used for
    //the update operation

    byte[] bytes_ret = new byte[10];

    //1 Input Stream for insertion
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);

    //2 Input Stream for insertion
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

    //Prepared Statement used to insert the data
    PreparedStatement ps_sb = prep("dBlob");

    //first insert
    ps_sb.setInt(1, key);
    ps_sb.setBinaryStream(2,is1,BYTES1.length);
    ps_sb.executeUpdate();

    //second insert
    int key2 = requestKey();
    ps_sb.setInt(1, key2);
    ps_sb.setBinaryStream(2,is2,BYTES2.length);
    ps_sb.executeUpdate();

    ps_sb.close();

    //Update operation
    //use a different ResultSet variable so that the
    //other tests can go on unimpacted
    //we do not have set methods on Clob and Blob implemented
    //So query the first Clob from the database
    //update the second result set with this
    //Clob value

    ResultSet rs1 = fetch("dBlob", key);
    rs1.next();
    Blob blob = rs1.getBlob(1);
    rs1.close();

    rs1 = fetchUpd("dBlob", key2);
    rs1.next();
    rs1.updateBlob(1,blob);
    rs1.updateRow();
    rs1.close();

    //Query to see whether the data that has been updated
    //using the updateBlob method is the same
    //data that we expected

    rs1 = fetch("dBlob", key2);
    rs1.next();
    assertEquals(blob, rs1.getBlob(1));
    rs1.close();
}
 
Example 20
Source File: UnsupportedUpdateOperationResultSetTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBlobForColumnIndexWithInputStreamAndLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBlob(1, System.in, 100);
    }
}