Package java.sql

Examples of java.sql.PreparedStatement.executeUpdate()


        for (int i = 0; i < len; i++) {
            if (i % 1000 == 0) {
                // trace("[" + i + "/" + len + "] KB: " + MemoryUtils.getMemoryUsed());
            }
            prep.setInt(1, i);
            prep.executeUpdate();
        }
        int base = Utils.getMemoryUsed();
        stat.execute("create index idx_test_id on test(id)");
        System.gc();
        System.gc();
View Full Code Here


        // delete
        time = System.currentTimeMillis();
        prep = conn.prepareStatement("DELETE FROM TEST WHERE ID = ?");
        for (int i = 0; i < len; i++) {
            prep.setInt(1, random.nextInt(len));
            prep.executeUpdate();
            if (i % 50000 == 0) {
                trace("  " + (100 * i / len) + "%");
            }
        }
        printTimeMemory("delete", System.currentTimeMillis() - time);
View Full Code Here

        int ca = 1;
        prep.setString(ca++, "Paul");
        prep.setString(ca++, "Frank");
        prep.setString(ca++, "Paul");
        prep.setString(ca++, "Frank");
        prep.executeUpdate();
        prep.close();

        assertResult("Paul, Frank", stat, "SELECT full_name FROM test WHERE name = 'Paul'");

        prep = conn.prepareStatement("SELECT ? + ?");
View Full Code Here

    void first() throws SQLException {
        Connection c = base.getConnection();
        c.createStatement().execute("create table news(id identity, state int default 0, text varchar default '')");
        PreparedStatement prep = c.prepareStatement("insert into news() values()");
        for (int i = 0; i < newsCount; i++) {
            prep.executeUpdate();
        }
        c.createStatement().execute("update news set text = 'Text' || id");
        c.close();
    }
View Full Code Here

    private void insertOrder() throws SQLException {
        PreparedStatement prep = conn.prepareStatement("insert into orders(customer_id , total) values(?, ?)");
        prep.setInt(1, random.nextInt(getCustomerCount()));
        BigDecimal total = new BigDecimal("0");
        prep.setBigDecimal(2, total);
        prep.executeUpdate();
        ResultSet rs = prep.getGeneratedKeys();
        rs.next();
        int orderId = rs.getInt(1);
        int lines = random.nextInt(20);
        for (int i = 0; i < lines; i++) {
View Full Code Here

                }
            } else {
                PreparedStatement prep = conn.prepareStatement("UPDATE NEWS SET STATE = ? WHERE FID = ?");
                prep.setInt(1, random.nextInt(100));
                prep.setInt(2, random.nextInt(len));
                int count = prep.executeUpdate();
                if (count != 1) {
                    throw new SQLException("expected one row, got " + count);
                }
            }
        }
View Full Code Here

        int rows = 0;
        try {
            stmt = conn.prepareStatement(sql);
            fillStatement(stmt, params);
            verboseQuery(sql, params);
            rows = stmt.executeUpdate();
        } catch (SQLException e) {
            rethrow(e, sql, params);
        } finally {
            close(stmt);
        }
View Full Code Here

    int executeUpdate() {
        PreparedStatement ps = null;
        try {
            ps = prepare(false);
            return ps.executeUpdate();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            JdbcUtils.closeSilently(ps);
        }
View Full Code Here

    long executeInsert() {
        PreparedStatement ps = null;
        try {
            ps = prepare(true);
            ps.executeUpdate();
            long identity = -1;
            ResultSet rs = ps.getGeneratedKeys();
            if (rs != null && rs.next()) {
                identity = rs.getLong(1);
            }
View Full Code Here

                }
                if (delete && random.nextInt(10) == 1) {
                    if (random.nextInt(4) == 1) {
                        try {
                            prepDeleteAllButOne.setString(1, prefix + y);
                            int deleted = prepDeleteAllButOne.executeUpdate();
                            if (deleted < count - 1) {
                                printError(seed, "deleted:" + deleted + " i:" + i);
                            }
                            count -= deleted;
                        } catch (SQLException e) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.