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

The following examples show how to use java.sql.ResultSet#updateBinaryStream() . 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: BLOBTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests updating the Blob using result set update methods.
 * @param rs result set, currently positioned on row to be updated
 * @param newVal new value in val column and blob data
 * @param newSize new size of Blob
 * @exception SQLException causes test to fail with error
 * @exception IOException causes test to fail with error
 */
private void testUpdateBlobWithResultSetMethods(final ResultSet rs,
                                                final int newVal,
                                                final int newSize) 
    throws SQLException, IOException
{
    int val = rs.getInt("VAL");
    int size = rs.getInt("LENGTH");
    println("VerifyBlob");
    verifyBlob(val, size, rs.getBlob("DATA"));
    
    println("UpdateBlob");
    final TestInputStream newStream = new TestInputStream(newSize, newVal);
    
    rs.updateInt("VAL", newVal);
    rs.updateInt("LENGTH", newSize);
    rs.updateBinaryStream("DATA", newStream, newSize);
    rs.updateRow();
    
    println("Verify updated blob with another query");
    verifyNewValueInTable(newVal, newSize);
}
 
Example 2
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test <code>updateBinaryStream</code> on a BINARY column, without
 * specifying length of inputstream.
 */
public void testUpdateBinaryStreamLengthless()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

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

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

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

    rs1 = fetch("dLongBit", 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 5 votes vote down vote up
/**
 * Test <code>updateBinaryStream</code> on a BLOB column, without
 * specifying length of inputstream.
 */
public void testUpdateBinaryStreamLengthlessBlob()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    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.updateBinaryStream(1, is2);
    rs1.updateRow();
    rs1.close();

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

    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
/**
 * Test <code>updateBinaryStream</code> on a BLOB column, without
 * specifying length of inputstream.
 */
public void testUpdateBinaryStreamLengthlessBlob()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    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.updateBinaryStream(1, is2);
    rs1.updateRow();
    rs1.close();

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

    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 5
Source File: WebSphereMsSqlServerDbmsSupport.java    From iaf with Apache License 2.0 5 votes vote down vote up
public void updateBlob(ResultSet rs, String column, Object blobUpdateHandle) throws SQLException, JdbcException {
	File blobFile = (File)blobUpdateHandle;
	try {
		InputStream is = new FileInputStream(blobFile); 
		rs.updateBinaryStream(column, is, (int)blobFile.length());
	} catch (FileNotFoundException e) {
		throw new JdbcException("cannot read blob for column ["+column+"] from file ["+blobFile.toString()+"]",e);
	}
}
 
Example 6
Source File: WebSphereMsSqlServerDbmsSupport.java    From iaf with Apache License 2.0 5 votes vote down vote up
public void updateBlob(ResultSet rs, int column, Object blobUpdateHandle) throws SQLException, JdbcException {
	File blobFile = (File)blobUpdateHandle;
	try {
		InputStream is = new FileInputStream(blobFile); 
		rs.updateBinaryStream(column, is, (int)blobFile.length());
	} catch (FileNotFoundException e) {
		throw new JdbcException("cannot read blob for column ["+column+"] from file ["+blobFile.toString()+"]",e);
	}
}
 
Example 7
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testUpdateBinaryStreamLengthlessParameterName()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

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

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

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

    rs1 = fetch("dLongBit", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 8
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test <code>updateBinaryStream</code> on a BLOB column, without
 * specifying length of inputstream.
 */
public void testUpdateBinaryStreamLengthlessBlob()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    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.updateBinaryStream(1, is2);
    rs1.updateRow();
    rs1.close();

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

    rs1 = fetch("dBlob", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 9
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testUpdateBinaryStreamLengthlessParameterName()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

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

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

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

    rs1 = fetch("dLongBit", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 10
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test <code>updateBinaryStream</code> on a BINARY column, without
 * specifying length of inputstream.
 */
public void testUpdateBinaryStreamLengthless()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

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

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

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

    rs1 = fetch("dLongBit", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 11
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testUpdateBinaryStreamLengthlessParameterName()
        throws IOException, SQLException {
    InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
    // InputStream used for update.
    InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);

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

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

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

    rs1 = fetch("dLongBit", key);
    rs1.next();
    assertEquals(new ByteArrayInputStream(BYTES2), rs1.getBinaryStream(1));
    rs1.close();
}
 
Example 12
Source File: BadResultSetAccessTest.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@NoWarning("SQL")
public void test4(ResultSet rs) throws SQLException {
    rs.updateBinaryStream(1, null, 0);
}
 
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 assertUpdateBinaryStreamForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBinaryStream(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 assertUpdateBinaryStreamForColumnIndexWithLongLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBinaryStream(1, System.in, 1L);
    }
}
 
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 assertUpdateBinaryStreamForColumnLabelWithIntegerLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBinaryStream("label", System.in, 1);
    }
}
 
Example 16
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBinaryStreamForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBinaryStream("label", System.in);
    }
}
 
Example 17
Source File: BlobTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Test for bug #42711 from derby's ResultSetTest. */
public void SW_testUpdateBinaryStream() throws Exception {
  setupConnection();
  final Statement stmt = getStatement();
  stmt.execute("create table UpdateTestTableResultSet ("
      + "sno int not null unique," + "dBlob BLOB," + "dClob CLOB,"
      + "dLongVarchar LONG VARCHAR," + "dLongBit LONG VARCHAR FOR BIT DATA)"+ getSuffix());

  // 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];

  // Input Stream inserted initially
  InputStream is = new java.io.ByteArrayInputStream(BYTES1);

  // InputStream that is used for update
  InputStream is_for_update = new java.io.ByteArrayInputStream(BYTES2);

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

  // Update operation
  // use a different ResultSet variable so that the
  // other tests can go on unimpacted

  ResultSet rs1 = fetchUpd("dLongBit", key);
  rs1.next();
  rs1.updateBinaryStream(1, is_for_update, BYTES2.length);
  rs1.updateRow();
  rs1.close();

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

  rs1 = fetch("dLongBit", key);
  rs1.next();
  InputStream is_ret = rs1.getBinaryStream(1);

  is_ret.read(bytes_ret);
  is_ret.close();

  for (int i = 0; i < BYTES2.length; i++) {
    assertEquals("Error in updateBinaryStream", BYTES2[i], bytes_ret[i]);
  }
  rs1.close();

  stmt.execute("drop table UpdateTestTableResultSet");
  this.waitTillAllClear();
  stmt.close();
}
 
Example 18
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
 * updateBinaryStream
 *
 * @throws SQLException if some error occurs while calling the method
 */

public void testUpdateBinaryStreamStringParameterName()
throws Exception {
    //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];

    //Input Stream inserted initially
    InputStream is = new java.io.ByteArrayInputStream(BYTES1);

    //InputStream that is used for update
    InputStream is_for_update = new
            java.io.ByteArrayInputStream(BYTES2);

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

    //Update operation
    //Update operation
    //use a different ResultSet variable so that the
    //other tests can go on unimpacted

    ResultSet rs1 = fetchUpd("dLongBit", key);
    rs1.next();
    rs1.updateBinaryStream("dLongBit",is_for_update,(int)BYTES2.length);
    rs1.updateRow();
    rs1.close();

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

    rs1 = fetch("dLongBit", key);
    rs1.next();
    InputStream is_ret = rs1.getBinaryStream(1);

    is_ret.read(bytes_ret);
    is_ret.close();

    for(int i=0;i<BYTES2.length;i++) {
        assertEquals("Error in updateBinaryStream",BYTES2[i],bytes_ret[i]);
    }
    rs1.close();
}
 
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
 * updateBinaryStream
 *
 * @throws SQLException if some error occurs while calling the method
 */

public void testUpdateBinaryStream()
throws Exception {
    //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];

    //Input Stream inserted initially
    InputStream is = new java.io.ByteArrayInputStream(BYTES1);

    //InputStream that is used for update
    InputStream is_for_update = new
            java.io.ByteArrayInputStream(BYTES2);

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

    //Update operation
    //use a different ResultSet variable so that the
    //other tests can go on unimpacted

    ResultSet rs1 = fetchUpd("dLongBit", key);
    rs1.next();
    rs1.updateBinaryStream(1,is_for_update,(int)BYTES2.length);
    rs1.updateRow();
    rs1.close();

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

    rs1 = fetch("dLongBit", key);
    rs1.next();
    InputStream is_ret = rs1.getBinaryStream(1);

    is_ret.read(bytes_ret);
    is_ret.close();

    for(int i=0;i<BYTES2.length;i++) {
        assertEquals("Error in updateBinaryStream",BYTES2[i],bytes_ret[i]);
    }
    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 assertUpdateBinaryStreamForColumnIndexWithIntegerLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBinaryStream(1, System.in, 1);
    }
}