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

The following examples show how to use java.sql.ResultSet#updateBigDecimal() . 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: SQLDistTxTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected boolean updateURSRowTx(ResultSet updatableRs, int tid) {
  try {
    int cid = updatableRs.getInt("CID");
    BigDecimal sec = updatableRs.getBigDecimal("SECURITIES").add(
        new BigDecimal(tid));
    updatableRs.updateBigDecimal("SECURITIES", sec);
    updatableRs.updateRow();
    Log.getLogWriter().info("update trade.networth set securities to be " + sec 
        + " for cid: " + cid);
  } catch (SQLException se) {
    if (se.getSQLState().equals("X0Z02")) {
      SQLHelper.printSQLException(se);
      return false; // expected updatable result set
    } else
      SQLHelper.handleSQLException(se);
  }
  return true;
}
 
Example 2
Source File: UpdateXXXTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests calling update on all columns of the row.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void jdbc2testUpdateBigDecimal() 
    throws SQLException
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery(SELECT_STMT);
    rs.next();

    for (int i = 1; i <= COLUMNS; i++) {
        rs.updateBigDecimal(i, BigDecimal.valueOf(2L));
        assertEquals("Expected rs.getBigDecimal(" + i + 
                     ") to match updated value", 2, 
                     rs.getBigDecimal(i).intValue());
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreUpdated();
    
    s.close();
}
 
Example 3
Source File: UpdateXXXTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests calling update on all columns of the row.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void jdbc2testUpdateBigDecimal() 
    throws SQLException
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery(SELECT_STMT);
    rs.next();

    for (int i = 1; i <= COLUMNS; i++) {
        rs.updateBigDecimal(i, BigDecimal.valueOf(2L));
        assertEquals("Expected rs.getBigDecimal(" + i + 
                     ") to match updated value", 2, 
                     rs.getBigDecimal(i).intValue());
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreUpdated();
    
    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 update on all columns of the row.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void jdbc2testUpdateBigDecimal() 
    throws SQLException
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = s.executeQuery(SELECT_STMT);
    rs.next();

    for (int i = 1; i <= COLUMNS; i++) {
        rs.updateBigDecimal(i, BigDecimal.valueOf(2L));
        assertEquals("Expected rs.getBigDecimal(" + i + 
                     ") to match updated value", 2, 
                     rs.getBigDecimal(i).intValue());
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreUpdated();
    
    s.close();
}
 
Example 5
Source File: SQLDistTxTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected boolean updateRowSFU_URSTx(ResultSet updatableRs, int tid) {
  try {
    int cid = updatableRs.getInt("CID");
    BigDecimal sec = updatableRs.getBigDecimal("SECURITIES").add(
        new BigDecimal(tid));
    updatableRs.updateBigDecimal("SECURITIES", sec);
    updatableRs.updateRow();
    Log.getLogWriter().info(
        "update trade.networth set securities to be " + sec + " for cid: "
            + cid);
  } catch (SQLException se) {
    if (isHATest && SQLHelper.gotTXNodeFailureException(se)) {
      Log.getLogWriter().info(
          "got node failure exception, needs to retry the op");
      return false;
    }

    SQLHelper.handleSQLException(se);
  }
  return true;
}
 
Example 6
Source File: ParameterMappingTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private void assertUpdateState(
    ResultSet rs,
    String colName,
    BigDecimal value,
    String expected) throws SQLException {

    try {
        rs.updateBigDecimal(colName, value);
        fail("exception expected");
    } catch (SQLException e) {
        println(e.toString());
        assertSQLState(expected, e);
    }
}
 
Example 7
Source File: BigDecimalHandler.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(int columnIndex, BigDecimal x)
 * @param rs ResultSet
 * @param columnIndex Column Index
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, int columnIndex, String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnIndex, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnIndex, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 8
Source File: BigDecimalHandler.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(int columnIndex, BigDecimal x)
 * @param rs ResultSet
 * @param columnIndex Column Index
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, int columnIndex, String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnIndex, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnIndex, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 9
Source File: BigDecimalHandler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(int columnIndex, BigDecimal x)
 * @param rs ResultSet
 * @param columnIndex Column Index
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, int columnIndex, String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnIndex, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnIndex, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 10
Source File: BigDecimalHandler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(String columnName, BigDecimal x)
 * @param rs ResultSet
 * @param columnName Column Name
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, String columnName,String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnName, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnName, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 11
Source File: BigDecimalHandler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(int columnIndex, BigDecimal x)
 * @param rs ResultSet
 * @param columnIndex Column Index
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, int columnIndex, String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnIndex, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnIndex, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 12
Source File: BigDecimalHandler.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(String columnName, BigDecimal x)
 * @param rs ResultSet
 * @param columnName Column Name
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, String columnName,String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnName, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnName, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 13
Source File: BigDecimalHandler.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(String columnName, BigDecimal x)
 * @param rs ResultSet
 * @param columnName Column Name
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, String columnName,String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnName, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnName, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 14
Source File: BigDecimalHandler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(String columnName, BigDecimal x)
 * @param rs ResultSet
 * @param columnName Column Name
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, String columnName,String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnName, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnName, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
Example 15
Source File: BigDecimalHandler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** This method is a wrapper for ResultSet method 
 * updateBigDecimal(int columnIndex, BigDecimal x)
 * @param rs ResultSet
 * @param columnIndex Column Index
 * @param bdString String to be used in updateXXX method
 * @throws SQLException
 */
public static void updateBigDecimalString(ResultSet rs, int columnIndex, String bdString) throws SQLException{
			
	switch(representation){
		case BIGDECIMAL_REPRESENTATION:
			BigDecimal bd = (bdString == null) ? null : new BigDecimal(bdString);
			rs.updateBigDecimal(columnIndex, bd);
			break;
		case STRING_REPRESENTATION:
			rs.updateString(columnIndex, bdString);
			break;
		default:	
			new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
	}
}
 
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 assertUpdateBigDecimalForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBigDecimal("label", new BigDecimal("1"));
    }
}
 
Example 17
Source File: SelectForUpdateTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void _testSelectForUpdateForDebugging() throws Exception {
  Connection conn = getConnection();
  Statement stmtForTableAndInsert = conn.createStatement();
  stmtForTableAndInsert.execute("create table Employee"
      + "(firstname varchar(50) not null, lastname varchar(50) not null, "
      + "workdept varchar(50), bonus decimal(10,4), "
      + "primary key (firstname, lastname))");
  stmtForTableAndInsert
      .execute("insert into employee values('neeraj', 'kumar', 'rnd', 0.0), "
          + "('asif', 'shahid', 'rnd', 1.0), "
          + "('dada', 'ji', 'rnd', 2.0), ('sum', 'wale', 'rnd', 3.0)");
  conn.commit();
  // conn.setAutoCommit(false);
  // Create the statement with concurrency mode CONCUR_UPDATABLE
  // to allow result sets to be updatable
  conn.setTransactionIsolation(getIsolationLevel());
  Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  // Statement stmt = conn.createStatement();
  // Updatable statements have some requirements
  // for example, select must be on a single table
  // Only bonus can be updated
  // ResultSet uprs = stmt.executeQuery(
  // "SELECT WORKDEPT, BONUS /*, firstname, LastNaME*/ " +
  // "FROM EMPLOYEE where lastname = 'kumar' FOR UPDATE of BONUS");

  // Only bonus can be updated
  ResultSet uprs = stmt.executeQuery("SELECT workdept, bonus "
      + "FROM EMPLOYEE where lastname = 'kumar' FOR UPDATE of BONUS");
  // ResultSet uprs = stmt.executeQuery(
  // "SELECT firstname, count(*) " +
  // "FROM EMPLOYEE group by firstname FOR UPDATE of BONUS"); // Only bonus
  // can be updated

  while (uprs.next()) {
    uprs.getString("WORKDEPT");
    BigDecimal bonus = uprs.getBigDecimal("BONUS");
    // if (workDept.equals(theDept)) {
    if (true) {
      // if the current row meets our criteria,
      // update the updatable column in the row
      uprs.updateBigDecimal("BONUS", bonus.add(BigDecimal.valueOf(250L)));
      // uprs.updateBigDecimal("BONUS", null);
      uprs.updateRow();
      // System.out.println("Updating bonus for employee:" +
      // firstnme +" "+ lastName);
    }
  }
  conn.commit(); // commit the transaction
  // close object
  uprs.close();
  ResultSet rs = stmt.executeQuery("select * from employee");
  while (rs.next()) {
    System.out.println(rs.getString(1) + ", " + rs.getString(2) + ", "
        + rs.getString(3) + ", " + rs.getBigDecimal(4));
  }
  conn.commit();
  stmt.close();
  // Close connection if the application does not need it any more
  conn.close();

}
 
Example 18
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 assertUpdateBigDecimalForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBigDecimal(1, new BigDecimal("1"));
    }
}
 
Example 19
Source File: SelectForUpdateTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void _testSelectForUpdateForDebugging() throws Exception {
  Connection conn = getConnection();
  Statement stmtForTableAndInsert = conn.createStatement();
  stmtForTableAndInsert.execute("create table Employee"
      + "(firstname varchar(50) not null, lastname varchar(50) not null, "
      + "workdept varchar(50), bonus decimal(10,4), "
      + "primary key (firstname, lastname))");
  stmtForTableAndInsert
      .execute("insert into employee values('neeraj', 'kumar', 'rnd', 0.0), "
          + "('asif', 'shahid', 'rnd', 1.0), "
          + "('dada', 'ji', 'rnd', 2.0), ('sum', 'wale', 'rnd', 3.0)");
  conn.commit();
  // conn.setAutoCommit(false);
  // Create the statement with concurrency mode CONCUR_UPDATABLE
  // to allow result sets to be updatable
  conn.setTransactionIsolation(getIsolationLevel());
  Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  // Statement stmt = conn.createStatement();
  // Updatable statements have some requirements
  // for example, select must be on a single table
  // Only bonus can be updated
  // ResultSet uprs = stmt.executeQuery(
  // "SELECT WORKDEPT, BONUS /*, firstname, LastNaME*/ " +
  // "FROM EMPLOYEE where lastname = 'kumar' FOR UPDATE of BONUS");

  // Only bonus can be updated
  ResultSet uprs = stmt.executeQuery("SELECT workdept, bonus "
      + "FROM EMPLOYEE where lastname = 'kumar' FOR UPDATE of BONUS");
  // ResultSet uprs = stmt.executeQuery(
  // "SELECT firstname, count(*) " +
  // "FROM EMPLOYEE group by firstname FOR UPDATE of BONUS"); // Only bonus
  // can be updated

  while (uprs.next()) {
    uprs.getString("WORKDEPT");
    BigDecimal bonus = uprs.getBigDecimal("BONUS");
    // if (workDept.equals(theDept)) {
    if (true) {
      // if the current row meets our criteria,
      // update the updatable column in the row
      uprs.updateBigDecimal("BONUS", bonus.add(BigDecimal.valueOf(250L)));
      // uprs.updateBigDecimal("BONUS", null);
      uprs.updateRow();
      // System.out.println("Updating bonus for employee:" +
      // firstnme +" "+ lastName);
    }
  }
  conn.commit(); // commit the transaction
  // close object
  uprs.close();
  ResultSet rs = stmt.executeQuery("select * from employee");
  while (rs.next()) {
    System.out.println(rs.getString(1) + ", " + rs.getString(2) + ", "
        + rs.getString(3) + ", " + rs.getBigDecimal(4));
  }
  conn.commit();
  stmt.close();
  // Close connection if the application does not need it any more
  conn.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 assertUpdateBigDecimalForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBigDecimal("label", new BigDecimal("1"));
    }
}