Examples of JdbcRowSet


Examples of javax.sql.rowset.JdbcRowSet

    public void testAddJoinableRowSet_JdbcRowSet_Exception() throws Exception {
        /*
         * Test empty JdbcRowSet
         */
        JdbcRowSet jdbcRs = newJdbcRowSet();
        try {
            jrs.addRowSet(jdbcRs);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jdbcRs.setMatchColumn(1);
        try {
            jrs.addRowSet(jdbcRs);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.close();

        /*
         * Test JdbcRowSet filled with data
         */
        jrs = newJoinRowSet();
        jdbcRs = newJdbcRowSet();
        jdbcRs.setUrl(DERBY_URL);
        jdbcRs.setCommand("SELECT * FROM USER_INFO");
        jdbcRs.execute();
        try {
            jrs.addRowSet(jdbcRs);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jdbcRs.setMatchColumn(2);
        jrs.addRowSet(jdbcRs);
        jrs.close();
    }
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

    public void testAddJoinableRowSet_JdbcRowSet_Int_Exception()
            throws Exception {
        /*
         * Test empty JdbcRowSet
         */
        JdbcRowSet jdbcRs = newJdbcRowSet();
        if ("true".equals(System.getProperty("Testing Harmony"))) {
            try {
                jrs.addRowSet(jdbcRs, 1);
                fail("should throw SQLException");
            } catch (SQLException e) {
                // expected
            }
        } else {
            try {
                jrs.addRowSet(jdbcRs, 1);
                fail("should throw ClassCastException");
            } catch (ClassCastException e) {
                // expected
            }
        }
        jrs.close();

        /*
         * Test JdbcRowSet filled with data
         */
        jrs = newJoinRowSet();
        jdbcRs = newJdbcRowSet();
        jdbcRs.setUrl(DERBY_URL);
        jdbcRs.setCommand("SELECT * FROM USER_INFO");
        jdbcRs.execute();
        if ("true".equals(System.getProperty("Testing Harmony"))) {
            jrs.addRowSet(jdbcRs, 1);
        } else {
            try {
                jrs.addRowSet(jdbcRs, 1);
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

        /*
         * Add a JdbcRowSet which can't set Table Name
         */
        jrs = newJoinRowSet();
        JdbcRowSet jdbcRs = newJdbcRowSet();
        jdbcRs.setCommand("SELECT * FROM USER_INFO");
        jdbcRs.setUrl(DERBY_URL);
        jdbcRs.execute();
        jdbcRs.setMatchColumn(1);
        jrs.addRowSet(jdbcRs);
        // add a CachedRowSet with table name
        crset = newNoInitialInstance();
        crset.populate(st.executeQuery("SELECT * FROM BOOKS"));
        crset.setMatchColumn(1);
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

public class JdbcRowSetJoinTest extends CachedRowSetTestCase {

    public void testSetMatchColumn_Name() throws Exception {
        String name = null;
        JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
        JdbcRowSet jrs = newJdbcRowSet();
        /*
         * TODO spec: throw SQLException, RI throw NullPointerException, Harmony
         * follow spec
         */
        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            try {
                noInitalJrs.setMatchColumn(name);
                fail("Should throw NullPointerException");
            } catch (NullPointerException e) {
                // expected
            }
        } else {

            try {
                noInitalJrs.setMatchColumn(name);
                fail("Should throw SQLException");
            } catch (SQLException e) {
                // expected, Match columns should not be empty or null string
            }
        }

        try {
            noInitalJrs.setMatchColumn("");
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Match columns should not be empty or null string
        }

        noInitalJrs.setMatchColumn("not exist");
        String[] names = noInitalJrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(10, names.length);
        assertEquals("not exist", names[0]);
        for (int i = 1; i < names.length; i++) {
            assertNull(names[i]);
        }

        noInitalJrs.setMatchColumn("id");
        names = noInitalJrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(10, names.length);
        assertEquals("id", names[0]);
        for (int i = 1; i < names.length; i++) {
            assertNull(names[i]);
        }

        noInitalJrs.setMatchColumn(new String[] { "ID", "NAME" });

        names = null;

        try {
            noInitalJrs.setMatchColumn(names);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        names = noInitalJrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(12, names.length);
        assertEquals("ID", names[0]);
        assertEquals("NAME", names[1]);
        assertEquals("id", names[2]);

        for (int i = 3; i < names.length; i++) {
            assertNull(names[i]);
        }

        try {
            noInitalJrs.setMatchColumn(new String[] { "ID", "" });
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Match columns should not be empty or null string
        }

        try {
            noInitalJrs.setMatchColumn(new String[] { "ID", null });
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Match columns should not be empty or null string
        }

        noInitalJrs.setMatchColumn("NAME");
        names = noInitalJrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(12, names.length);
        assertEquals("NAME", names[0]);
        assertEquals("NAME", names[1]);
        assertEquals("id", names[2]);

        for (int i = 3; i < names.length; i++) {
            assertNull(names[i]);
        }

        if (!"true".equals(System.getProperty("Testing Harmony"))) {
            try {
                jrs.setMatchColumn(name);
                fail("Should throw NullPointerException");
            } catch (NullPointerException e) {
                // expected
            }
        } else {

            try {
                jrs.setMatchColumn(name);
                fail("Should throw SQLException");
            } catch (SQLException e) {
                // expected, Match columns should not be empty or null string
            }
        }

        try {
            jrs.setMatchColumn("");
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Match columns should not be empty or null string
        }

        jrs.setMatchColumn("not exist");
        names = jrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(10, names.length);
        assertEquals("not exist", names[0]);
        for (int i = 1; i < names.length; i++) {
            assertNull(names[i]);
        }

        jrs.setMatchColumn("id");
        names = jrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(10, names.length);
        assertEquals("id", names[0]);
        for (int i = 1; i < names.length; i++) {
            assertNull(names[i]);
        }

        jrs.setMatchColumn(new String[] { "ID", "NAME" });
        names = jrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(12, names.length);
        assertEquals("ID", names[0]);
        assertEquals("NAME", names[1]);
        assertEquals("id", names[2]);

        for (int i = 3; i < names.length; i++) {
            assertNull(names[i]);
        }

        try {
            jrs.setMatchColumn(new String[] { "ID", "" });
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Match columns should not be empty or null string
        }

        try {
            jrs.setMatchColumn(new String[] { "ID", null });
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Match columns should not be empty or null string
        }

        jrs.setMatchColumn("NAME");
        names = jrs.getMatchColumnNames();
        assertNotNull(names);
        assertEquals(12, names.length);
        assertEquals("NAME", names[0]);
        assertEquals("NAME", names[1]);
        assertEquals("id", names[2]);
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

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

    public void testInsertRow_Multi() throws Exception {
        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.updateInt(1, 6);
        jrs.updateString(2, "insert6");
        jrs.insertRow();
        jrs.updateInt(1, 7);
        jrs.updateString(2, "insert7");
        jrs.insertRow();
        jrs.moveToCurrentRow();

        int index = 0;
        jrs.beforeFirst();
        while (jrs.next()) {
            index++;
            assertEquals(index, jrs.getInt(1));
        }
        assertEquals(7, index);

        jrs.close();

        /*
         * Check database
         */
        rs = st
                .executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME LIKE 'insert%'");
        assertTrue(rs.next());
        assertEquals(3, rs.getInt(1));

        /*
         * Change another way to insert multiple rows
         */
        jrs = newJdbcRowSet();
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        assertTrue(jrs.absolute(7));
        jrs.moveToInsertRow();
        jrs.updateInt(1, 8);
        jrs.updateString(2, "insert8");
        jrs.insertRow();
        jrs.moveToInsertRow();
        jrs.updateInt(1, 9);
        jrs.updateString(2, "insert9");
        jrs.insertRow();
        jrs.moveToInsertRow();
        jrs.updateInt(1, 10);
        jrs.updateString(2, "insert10");
        jrs.insertRow();
        jrs.moveToCurrentRow();

        /*
         * Check JdbcRowSet
         */
        assertEquals(7, jrs.getInt(1));
        index = 7;
        while (jrs.next()) {
            index++;
            assertEquals(index, jrs.getInt(1));
        }
        assertEquals(10, index);

        jrs.close();

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

Examples of javax.sql.rowset.JdbcRowSet

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

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

        jrs.moveToInsertRow();
        try {
            jrs.cancelRowUpdates();
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.moveToCurrentRow();

        assertTrue(jrs.absolute(3));
        jrs.updateString(2, "update3");
        jrs.updateRow();
        assertTrue(jrs.rowUpdated());
        assertEquals("update3", jrs.getString(2));
        jrs.cancelRowUpdates();
        assertEquals("update3", jrs.getString(2));

        assertTrue(jrs.next());
        assertEquals(4, jrs.getInt(1));
        jrs.updateString(2, "update4");
        assertFalse(jrs.rowUpdated());
        assertEquals("update4", jrs.getString(2));
        jrs.cancelRowUpdates();
        assertEquals("test4", jrs.getString(2));

        jrs.close();

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

Examples of javax.sql.rowset.JdbcRowSet

        assertTrue(rs.next());
        assertEquals("update3", rs.getString(2));
    }

    public void testFindColumn() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        try {
            jrs.findColumn("abc");
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();

        assertEquals(1, jrs.findColumn("ID"));
        try {
            jrs.findColumn("abc");
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        jrs.close();
    }
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

        jrs.close();
    }

    public void testGetStatement() throws Exception {
        JdbcRowSet jrs = newJdbcRowSet();
        assertNull(jrs.getStatement());
        jrs.setCommand("SELECT * FROM USER_INFO");
        jrs.setUrl(DERBY_URL);
        jrs.execute();
        assertTrue(jrs.getStatement() instanceof PreparedStatement);

        jrs.close();

        try {
            assertNull(jrs.getStatement());
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
    }
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

            // expected
        }
    }

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

        assertTrue(jrs.getAutoCommit());
        assertTrue(jrs.absolute(3));
        jrs.updateString(2, "update3");
        jrs.updateRow();
        jrs.rollback();

        // after rollback, resultset is closed
        assertNull(jrs.getStatement());
        try {
            jrs.getString(2);
            fail("should throw exception");
        } catch (NullPointerException e) {
            // expected
        }

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

        jrs.close();

        /*
         * TODO Check database. The database is supposed to has been updated.
         * However, it's not.
         */
 
View Full Code Here

Examples of javax.sql.rowset.JdbcRowSet

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

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

        jrs.setAutoCommit(false);
        assertFalse(jrs.getAutoCommit());
        assertTrue(jrs.absolute(3));
        jrs.updateString(2, "update3");
        jrs.updateRow();
        jrs.commit();
        jrs.rollback();

        /*
         * TODO why throw NullPointerException after call rollback()?
         */
        try {
            jrs.absolute(1);
            fail("should throw exception");
        } catch (NullPointerException e) {
            // expected
        }

        jrs.close();

        /*
         * Check database
         */
        rs = st
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.