Package javax.sql.rowset

Examples of javax.sql.rowset.JdbcRowSet


    /**
     * @tests javax.sql.rowset.JdbcRowTest.setShowDeleted() and
     *        javax.sql.rowset.JdbcRowTest.getShowDeleted().
     */
    public void testShowDeleted() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();

        boolean showDeleted = jrs.getShowDeleted();
        assertFalse("The default value is false.", showDeleted);

        jrs.setUrl(DERBY_URL);
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.execute();

        // Deletes the 4th row.
        jrs.absolute(4);
        jrs.deleteRow();
        try {
            jrs.getInt(1);
            fail("Should throw SQLException " + "since no current row.");
        } catch (SQLException e) {
            // Expected.
        }

        jrs.first();
        int index = 0;
        while (jrs.next()) {
            index++;
        }

        assertEquals(3, index);

        jrs.setShowDeleted(true);
        assertTrue(jrs.getShowDeleted());

        jrs.absolute(3);
        jrs.deleteRow();
        jrs.first();
        index = 0;
        while (jrs.next()) {
            index++;
        }

        assertEquals("The deleted row should still be showed", 3, index);

        jrs.close();
    }
View Full Code Here


        jrs.close();
    }

    public void testExecute_SelectCmd() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO WHERE ID > ?");
        jrs.setUrl(DERBY_URL);
        jrs.setInt(1, 1);
        jrs.execute();

        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
        assertEquals(ResultSet.CONCUR_UPDATABLE, jrs.getConcurrency());
        assertTrue(jrs.getAutoCommit());
        assertTrue(jrs.first());
        assertEquals(2, jrs.getInt(1));
        assertTrue(jrs.absolute(2));
        assertEquals(3, jrs.getInt(1));
        assertTrue(jrs.last());
        assertEquals(4, jrs.getInt(1));
        assertTrue(jrs.previous());
        assertEquals(3, jrs.getInt(1));
        assertTrue(jrs.relative(-1));
        assertEquals(2, jrs.getInt(1));
        jrs.close();
    }
View Full Code Here

        assertEquals(2, jrs.getInt(1));
        jrs.close();
    }

    public void testExecute_UpdateCmd() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("Update User_INFO set Name= ? Where ID= ? ");
        jrs.setUrl(DERBY_URL);
        jrs.setString(1, "update");
        jrs.setInt(2, 3);
        try {
            jrs.execute();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.close();
    }
View Full Code Here

        }
        jrs.close();
    }

    public void testExecute_DeleteCmd() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("DELETE FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        try {
            jrs.execute();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.close();
    }
View Full Code Here

        }
        jrs.close();
    }

    public void testExecute_InsertCmd() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("insert into USER_INFO(ID,NAME) values (6,'insert6')");
        jrs.setUrl(DERBY_URL);
        try {
            jrs.execute();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.close();
    }
View Full Code Here

        }
        jrs.close();
    }

    public void testUpdateRow_Normal() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        assertTrue(jrs.absolute(3));
        assertEquals(3, jrs.getInt(1));
        assertEquals("test3", jrs.getString(2));
        jrs.updateString(2, "update3");
        assertFalse(jrs.rowUpdated());
        jrs.updateRow();
        assertTrue(jrs.rowUpdated());
        assertEquals("update3", jrs.getString(2));

        jrs.close();

        // check db
        rs = st
                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update3'");
        assertTrue(rs.next());
View Full Code Here

        assertTrue(rs.next());
        assertEquals(1, rs.getInt(1));
    }

    public void testUpdateRow_Exception() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        assertTrue(jrs.absolute(-2));
        assertEquals("test3", jrs.getString(2));
        jrs.updateRow();
        assertFalse(jrs.rowUpdated());

        jrs.updateString(2, "too looooooooooooooooooooong");
        try {
            jrs.updateRow();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        try {
            assertFalse(jrs.rowUpdated());
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        try {
            assertTrue(jrs.absolute(1));
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        jrs.close();
    }
View Full Code Here

        jrs.close();
    }

    public void testDeleteRow() throws Exception {
        insertMoreData(6);
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        assertTrue(jrs.first());
        jrs.deleteRow();

        try {
            jrs.getInt(1);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        jrs.close();

        /*
         * Check database
         */
        rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
View Full Code Here

    public void testInsertRow_Single() throws Exception {
        /*
         * In JdbcRowSet, the inserted row is the last row. The behavior is the
         * same as ResultSet.
         */
        JdbcRowSet jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        jrs.moveToInsertRow();
        jrs.updateInt(1, 5);
        jrs.updateString(2, "insert5");
        jrs.insertRow();
        jrs.moveToCurrentRow();

        // check the inserted row
        assertTrue(jrs.absolute(5));
        /*
         * If uncommenting the following line, then the inserted row which ID is
         * 6 would be invisible to JdbcRowSet.
         */
        // assertTrue(jrs.isLast());
        assertEquals(5, jrs.getInt(1));

        jrs.moveToInsertRow();
        jrs.updateInt(1, 6);
        jrs.updateString(2, "insert6");
        jrs.insertRow();
        jrs.moveToCurrentRow();

        assertTrue(jrs.last());
        assertEquals(6, jrs.getInt(1));
        assertTrue(jrs.previous());
        assertEquals(5, jrs.getInt(1));

        jrs.close();

        // check db
        rs = st
                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'insert5' OR NAME = 'insert6'");
        assertTrue(rs.next());
View Full Code Here

        return (JdbcRowSet) Class.forName("com.sun.rowset.JdbcRowSetImpl")
                .newInstance();
    }

    public void testBeforeInitial() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();

        // move cursor
        try {
            jrs.absolute(1);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.beforeFirst();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.afterLast();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
        try {
            jrs.last();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
        try {
            jrs.first();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
        try {
            jrs.isAfterLast();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
        try {
            jrs.isBeforeFirst();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
        try {
            jrs.isFirst();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
        try {
            jrs.isLast();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.getRow();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.getString(1);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        // get properties

        try {
            jrs.getConcurrency();
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            jrs.getFetchDirection();
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        assertEquals(0, jrs.getFetchSize());
        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
        assertNull(jrs.getTypeMap());
        assertTrue(jrs.getEscapeProcessing());

        // set properties
        jrs.setConcurrency(RowSet.CONCUR_UPDATABLE);
        jrs.setType(ResultSet.TYPE_FORWARD_ONLY);
        jrs.setEscapeProcessing(false);
        assertFalse(jrs.getEscapeProcessing());

        // JdbcRowSet methods
        try {
            jrs.getAutoCommit();
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            jrs.commit();
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            jrs.setAutoCommit(false);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            jrs.rollback();
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        assertNull(jrs.getRowSetWarnings());

        // update methods
        try {
            jrs.updateString(1, "test");
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.insertRow();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        jrs.close();

        try {
            jrs.clearWarnings();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.findColumn("ID");
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.wasNull();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.getMetaData();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }

        try {
            jrs.getWarnings();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Invalid state
        }
    }
View Full Code Here

TOP

Related Classes of javax.sql.rowset.JdbcRowSet

Copyright © 2018 www.massapicom. 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.