java.sql.ResultSet#updateBigDecimal ( )源码实例Demo

下面列出了java.sql.ResultSet#updateBigDecimal ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: UpdateXXXTest.java
/**
 * 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();
}
 
源代码2 项目: spliceengine   文件: UpdateXXXTest.java
/**
 * 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();
}
 
源代码3 项目: gemfirexd-oss   文件: SQLDistTxTest.java
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;
}
 
源代码4 项目: gemfirexd-oss   文件: UpdateXXXTest.java
/**
 * 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();
}
 
源代码5 项目: gemfirexd-oss   文件: SQLDistTxTest.java
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;
}
 
源代码6 项目: gemfirexd-oss   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码7 项目: gemfirexd-oss   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码8 项目: spliceengine   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码9 项目: spliceengine   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码10 项目: spliceengine   文件: ParameterMappingTest.java
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);
    }
}
 
源代码11 项目: gemfirexd-oss   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码12 项目: gemfirexd-oss   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码13 项目: gemfirexd-oss   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码14 项目: spliceengine   文件: BigDecimalHandler.java
/** 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();
	}
}
 
源代码15 项目: spliceengine   文件: BigDecimalHandler.java
/** 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();
	}
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBigDecimalForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBigDecimal(1, new BigDecimal("1"));
    }
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBigDecimalForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBigDecimal("label", new BigDecimal("1"));
    }
}
 
源代码18 项目: gemfirexd-oss   文件: SelectForUpdateTest.java
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();

}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateBigDecimalForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateBigDecimal("label", new BigDecimal("1"));
    }
}
 
源代码20 项目: gemfirexd-oss   文件: SelectForUpdateTest.java
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();

}