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

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

源代码1 项目: gemfirexd-oss   文件: UpdateXXXTest.java
/**
 * Tests calling updateDouble on all columns of the row.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void testUpdateDouble() 
    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.updateDouble(i, 2.0);
        assertEquals("Expected rs.getDouble(" + i + 
                     ") to match updated value", 2, (int) rs.getDouble(i));
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreUpdated();
    
    s.close();
}
 
源代码2 项目: gemfirexd-oss   文件: UpdateXXXTest.java
/**
 * Tests calling updateDouble on all columns of the row.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void testUpdateDouble() 
    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.updateDouble(i, 2.0);
        assertEquals("Expected rs.getDouble(" + i + 
                     ") to match updated value", 2, (int) rs.getDouble(i));
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreUpdated();
    
    s.close();
}
 
源代码3 项目: spliceengine   文件: UpdateXXXTest.java
/**
 * Tests calling updateDouble on all columns of the row.
 * @exception SQLException database access error. Causes test to 
 *                         fail with an error.
 */
public void testUpdateDouble() 
    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.updateDouble(i, 2.0);
        assertEquals("Expected rs.getDouble(" + i + 
                     ") to match updated value", 2, (int) rs.getDouble(i));
    }
    rs.updateRow();
    rs.close();
    checkColumnsAreUpdated();
    
    s.close();
}
 
源代码4 项目: spliceengine   文件: ParameterMappingTest.java
private void assertUpdateState(
    ResultSet rs,
    String colName,
    long value,
    double dvalue,
    int updateType,
    String expected) throws SQLException {

    try {
        switch (updateType) {
        case XXX_BYTE:
            rs.updateByte(colName, (byte)value);
            break;
        case XXX_SHORT:
            rs.updateShort(colName, (short)value);
        case XXX_INT:
            rs.updateInt(colName, (int)value);
            break;
        case XXX_LONG:
            rs.updateLong(colName, value);
            break;
        case XXX_FLOAT:
            rs.updateFloat(colName, (float)dvalue);
            break;
        case XXX_DOUBLE:
            rs.updateDouble(colName, dvalue);
            break;
        default:
            fail("wrong argument");
        }

        fail("exception expected");
    } catch (SQLException e) {
        println(e.toString());
        assertSQLState(expected, e);
    }
}
 
源代码5 项目: spliceengine   文件: RoutinesDefinersRightsTest.java
/**
 * Test that PHB can actually update using {@code ResultSet.insertRow},
 * {@code ResultSet.updateRow} and {@code ResultSet.deleteRow}.
 * <p/>
 * Aside: This test is somewhat artificial here, since the middle manager
 * would not be allowed to do this, presumably; just added here to test
 * this functionality (which was initially broken by the first patch for
 * DERBY-4551).
 * <p/>
 * The problem was that the nested statement contexts used for SQL
 * substatements generated for these ResultSet operations were not
 * correctly set up, so the effective user id would not be the DEFINER
 * (DBO), and authorization would fail. Cf DERBY-4551 and DERBY-3327
 * for more detail.
 */
public static void updateWage()
        throws SQLException
{
    Connection c = null;

    c = DriverManager.getConnection("jdbc:default:connection");
    Statement cStmt = c.createStatement(
        ResultSet.TYPE_SCROLL_INSENSITIVE,
        ResultSet.CONCUR_UPDATABLE);

    // Try nested statements by inserting, updating and deleting a bogus
    // row
    ResultSet rs = cStmt.executeQuery(
        "select * from s1.wages");
    assertTrue(rs.isBeforeFirst());
    rs.moveToInsertRow();
    rs.updateInt("EMPLOYEEID", 666);
    rs.updateInt("CATEGORY", 667);
    rs.updateDouble("SALARY", 666.0);
    rs.updateString("NAME", "N.N.");
    rs.insertRow();
    rs.close();

    rs = cStmt.executeQuery(
        "select * from s1.wages where name = 'N.N.'");
    rs.next();
    rs.updateDouble("SALARY", 666.1);
    rs.updateRow();
    rs.close();

    rs = cStmt.executeQuery(
        "select * from s1.wages where name = 'N.N.'");
    rs.next();
    rs.deleteRow();
    rs.close();

    cStmt.close();
    c.close();
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateDoubleForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateDouble(1, 1D);
    }
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateDoubleForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateDouble("label", 1D);
    }
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateDoubleForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateDouble(1, 1D);
    }
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateDoubleForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets) {
        each.updateDouble("label", 1D);
    }
}
 
源代码10 项目: tutorials   文件: JdbcLiveTest.java
@Test
public void whenInsertUpdateRecord_thenCorrect() throws SQLException {
    Statement stmt = con.createStatement();

    String insertSql = "INSERT INTO employees(name, position, salary) values ('john', 'developer', 2000)";
    stmt.executeUpdate(insertSql);

    String selectSql = "SELECT * FROM employees";
    ResultSet resultSet = stmt.executeQuery(selectSql);

    List<Employee> employees = new ArrayList<>();

    while (resultSet.next()) {
        Employee emp = new Employee();
        emp.setId(resultSet.getInt("emp_id"));
        emp.setName(resultSet.getString("name"));
        emp.setSalary(resultSet.getDouble("salary"));
        emp.setPosition(resultSet.getString("position"));
        employees.add(emp);
    }

    assertEquals("employees list size incorrect", 1, employees.size());
    assertEquals("name incorrect", "john", employees.iterator().next().getName());
    assertEquals("position incorrect", "developer", employees.iterator().next().getPosition());
    assertEquals("salary incorrect", 2000, employees.iterator().next().getSalary(), 0.1);

    Statement updatableStmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet updatableResultSet = updatableStmt.executeQuery(selectSql);

    updatableResultSet.moveToInsertRow();
    updatableResultSet.updateString("name", "mark");
    updatableResultSet.updateString("position", "analyst");
    updatableResultSet.updateDouble("salary", 2000);
    updatableResultSet.insertRow();

    String updatePositionSql = "UPDATE employees SET position=? WHERE emp_id=?";
    PreparedStatement pstmt = con.prepareStatement(updatePositionSql);
    pstmt.setString(1, "lead developer");
    pstmt.setInt(2, 1);

    String updateSalarySql = "UPDATE employees SET salary=? WHERE emp_id=?";
    PreparedStatement pstmt2 = con.prepareStatement(updateSalarySql);
    pstmt.setDouble(1, 3000);
    pstmt.setInt(2, 1);

    boolean autoCommit = con.getAutoCommit();

    try {
        con.setAutoCommit(false);
        pstmt.executeUpdate();
        pstmt2.executeUpdate();
        con.commit();
    } catch (SQLException exc) {
        con.rollback();
    } finally {
        con.setAutoCommit(autoCommit);
    }
}
 
源代码11 项目: gemfirexd-oss   文件: SQLDouble.java
/**
	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 final void setInto(ResultSet rs, int position) throws SQLException, StandardException {
	rs.updateDouble(position, value);
}
 
源代码12 项目: gemfirexd-oss   文件: SQLDouble.java
/**
	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 final void setInto(ResultSet rs, int position) throws SQLException, StandardException {
	rs.updateDouble(position, value);
}
 
源代码13 项目: spliceengine   文件: SQLDouble.java
/**
	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 final void setInto(ResultSet rs, int position) throws SQLException, StandardException {
	rs.updateDouble(position, value);
}