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

The following examples show how to use java.sql.ResultSet#updateObject() . 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: UpdateXXXTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests calling updateObject with a null value on all columns.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void testUpdateObjectWithNull() 
    throws SQLException
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery(SELECT_STMT);
    rs.next();

    Object value = null;
    
    for (int i = 1; i <= COLUMNS; i++) {
        rs.updateObject(i, value);
        assertNull("Expected rs.getObject(" + i + ") to be null", 
                   rs.getObject(i));
        assertTrue("Expected rs.wasNull() to return true",
                   rs.wasNull());
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreNull();
    
    s.close();
}
 
Example 2
Source File: AdjustOrderInAVDisplayValue.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
private void adjustTable(final Connection conn, final String table) throws Exception {

        System.out.println("Adjusting table " + table);

        Statement sta = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet rs = sta.executeQuery("SELECT * FROM " + table + " WHERE DISPLAYVAL is not null");

        while (rs.next()) {

            final Object pk = rs.getObject("ATTRVALUE_ID");
            final String i18n = rs.getString("DISPLAYVAL");
            final String model = adjustValue(i18n);
            if (model != null && !model.equals(i18n)) {
                rs.updateObject("DISPLAYVAL", model);
                rs.updateRow();
                System.out.println("Adjusting object(" + pk + ") val: " + model);
            }
        }

        sta.close();
        conn.commit();

    }
 
Example 3
Source File: UpdateXXXTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests calling updateObject with a null value on all columns.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void testUpdateObjectWithNull() 
    throws SQLException
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery(SELECT_STMT);
    rs.next();

    Object value = null;
    
    for (int i = 1; i <= COLUMNS; i++) {
        rs.updateObject(i, value);
        assertNull("Expected rs.getObject(" + i + ") to be null", 
                   rs.getObject(i));
        assertTrue("Expected rs.wasNull() to return true",
                   rs.wasNull());
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreNull();
    
    s.close();
}
 
Example 4
Source File: UpdateXXXTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Tests calling updateObject with a null value on all columns.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void testUpdateObjectWithNull() 
    throws SQLException
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery(SELECT_STMT);
    rs.next();

    Object value = null;
    
    for (int i = 1; i <= COLUMNS; i++) {
        rs.updateObject(i, value);
        assertNull("Expected rs.getObject(" + i + ") to be null", 
                   rs.getObject(i));
        assertTrue("Expected rs.wasNull() to return true",
                   rs.wasNull());
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreNull();
    
    s.close();
}
 
Example 5
Source File: QueryReader.java    From sqlbuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Calls updateObject on the given ResultSet with the given value for the
 * position of this PlaceHolder.
 */
public void updateObject(Object value, ResultSet rs)
  throws SQLException
{
  if(value != null) {
    if(isInQuery()) {
      rs.updateObject(getIndex(), value);
    }
  } else {
    updateNull(rs);
  }
}
 
Example 6
Source File: BooleanValuesTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Verify fix for DERBY-5042, where updateBoolean() and updateObject()
 * would fail on a BOOLEAN column when using the client driver.
 */
public void test_5042_updateBoolean() throws SQLException {
    setAutoCommit(false);

    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                  ResultSet.CONCUR_UPDATABLE);
    s.execute("create table derby5042(b boolean, i int, c char(10))");

    ResultSet rs = s.executeQuery("select * from derby5042");

    // Test updateBoolean() on various column types
    rs.moveToInsertRow();
    rs.updateBoolean("B", true); // Used to fail with client driver
    rs.updateBoolean("I", true);
    rs.updateBoolean("C", true);
    rs.insertRow();

    // Test updateObject() with a java.lang.Boolean on various column types
    rs.moveToInsertRow();
    rs.updateObject("B", Boolean.FALSE); // Used to fail with client driver
    rs.updateObject("I", Boolean.FALSE);
    rs.updateObject("C", Boolean.FALSE);
    rs.insertRow();

    rs.close();

    JDBC.assertFullResultSet(
            s.executeQuery("select * from derby5042 order by 1,2,3"),
            new String[][]{
                {"false", "0", "false"},
                {"true", "1", "true"}});
}
 
Example 7
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 assertUpdateObjectForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject(1, new Object());
    }
}
 
Example 8
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 assertUpdateObjectForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject("label", new Object());
    }
}
 
Example 9
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 assertUpdateObjectForColumnIndexWithScaleOrLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject(1, new Object(), 1);
    }
}
 
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 assertUpdateObjectForColumnLabelWithScaleOrLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject("label", new Object(), 1);
    }
}
 
Example 11
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateObjectForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject(1, new Object());
    }
}
 
Example 12
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateObjectForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject("label", new Object());
    }
}
 
Example 13
Source File: UnsupportedUpdateOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateObjectForColumnIndexWithScaleOrLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject(1, new Object(), 1);
    }
}
 
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 assertUpdateObjectForColumnLabelWithScaleOrLength() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateObject("label", new Object(), 1);
    }
}
 
Example 15
Source File: DataType.java    From gemfirexd-oss with Apache License 2.0 votes vote down vote up
/**
	Set this value into a ResultSet for a subsequent ResultSet.insertRow
	or ResultSet.updateRow. This method will only be called for non-null values.

	@exception SQLException thrown by the ResultSet object
	@exception StandardException thrown by me accessing my value.
*/
public void setInto(ResultSet rs, int position) throws SQLException, StandardException {
	rs.updateObject(position, getObject());
}
 
Example 16
Source File: DataType.java    From gemfirexd-oss with Apache License 2.0 votes vote down vote up
/**
	Set this value into a ResultSet for a subsequent ResultSet.insertRow
	or ResultSet.updateRow. This method will only be called for non-null values.

	@exception SQLException thrown by the ResultSet object
	@exception StandardException thrown by me accessing my value.
*/
public void setInto(ResultSet rs, int position) throws SQLException, StandardException {
	rs.updateObject(position, getObject());
}