Package javax.sql.rowset

Examples of javax.sql.rowset.JdbcRowSet


        noInitalJrs = noInitalJdbcRowSet();

    }

    public void testGetMatchColumn() throws Exception {
        JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
        JdbcRowSet jrs = newJdbcRowSet();
        try {
            noInitalJrs.getMatchColumnIndexes();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Set Match columns before getting them
View Full Code Here


                .getMatchColumnNames());

    }

    public void testUnsetMatchColumn_Index_Unpopulate() throws Exception {
        JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
        JdbcRowSet jrs = newJdbcRowSet();
        int[] indexes = null;
        try {
            noInitalJrs.unsetMatchColumn(indexes);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
View Full Code Here

        assertEquals(2, indexes[5]);
        assertEquals(3, indexes[6]);
    }

    public void testUnsetMatchColumn_Index() throws Exception {
        JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
        JdbcRowSet jrs = newJdbcRowSet();
        int[] indexes = null;
        try {
            jrs.unsetMatchColumn(indexes);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        indexes = new int[0];

        jrs.unsetMatchColumn(indexes);

        indexes = new int[] { 1, 2, 3 };
        try {
            jrs.unsetMatchColumn(indexes);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        try {
            jrs.unsetMatchColumn(-2);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        try {
            jrs.unsetMatchColumn(0);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        jrs.setMatchColumn(1);
        try {
            jrs.unsetMatchColumn(2);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        jrs.unsetMatchColumn(1);

        try {
            indexes = jrs.getMatchColumnIndexes();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Set Match columns before getting them
        }

        jrs.setMatchColumn(new int[] { 1, 2, 3 });

        try {
            jrs.unsetMatchColumn(2);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }
        try {
            jrs.unsetMatchColumn(3);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        jrs.unsetMatchColumn(1);

        try {
            jrs.getMatchColumnIndexes();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Set Match columns before getting them
        }

        jrs.setMatchColumn(4);
        indexes = jrs.getMatchColumnIndexes();
        assertNotNull(indexes);
        assertEquals(13, indexes.length);
        assertEquals(4, indexes[0]);
        assertEquals(2, indexes[1]);
        assertEquals(3, indexes[2]);
        for (int i = 3; i < indexes.length; i++) {
            assertEquals(-1, indexes[i]);
        }

        try {
            jrs.unsetMatchColumn(2);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }
        try {
            jrs.unsetMatchColumn(3);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        jrs.setMatchColumn(new int[] { 5, 6 });
        try {
            jrs.unsetMatchColumn(2);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }
        try {
            jrs.unsetMatchColumn(3);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }
        try {
            jrs.unsetMatchColumn(4);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }
        try {
            jrs.unsetMatchColumn(6);
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Columns being unset are not the same as set
        }

        jrs.unsetMatchColumn(5);

        try {
            jrs.getMatchColumnIndexes();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Set Match columns before getting them
        }

        jrs.setMatchColumn(7);
        indexes = jrs.getMatchColumnIndexes();
        assertNotNull(indexes);
        assertEquals(15, indexes.length);
        assertEquals(7, indexes[0]);
        assertEquals(6, indexes[1]);
        assertEquals(4, indexes[2]);
        assertEquals(2, indexes[3]);
        assertEquals(3, indexes[4]);

        for (int i = 6; i < indexes.length; i++) {
            assertEquals(-1, indexes[i]);
        }

        jrs.unsetMatchColumn(new int[] { 7, 6 });
        try {
            jrs.getMatchColumnIndexes();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Set Match columns before getting them
        }

        jrs.setMatchColumn(new int[] { 7, 6 });
        indexes = jrs.getMatchColumnIndexes();

        assertNotNull(indexes);
        assertEquals(17, indexes.length);
        assertEquals(7, indexes[0]);
        assertEquals(6, indexes[1]);
        assertEquals(-1, indexes[2]);
        assertEquals(-1, indexes[3]);
        assertEquals(4, indexes[4]);
        assertEquals(2, indexes[5]);
        assertEquals(3, indexes[6]);

        jrs.unsetMatchColumn(new int[] { 7, 6, -1, -1, 4, 2, 3 });
        try {
            indexes = jrs.getMatchColumnIndexes();
            fail("Should throw SQLException");
        } catch (SQLException e) {
            // expected, Set Match columns before getting them
        }
    }
View Full Code Here

      try
      {
         Class.forName( JDBC_DRIVER ); // load database driver class

         // specify properties of JdbcRowSet
         JdbcRowSet rowSet = new JdbcRowSetImpl()
         rowSet.setUrl( DATABASE_URL ); // set database URL
         rowSet.setUsername( USERNAME ); // set username
         rowSet.setPassword( PASSWORD ); // set password
         rowSet.setCommand( "SELECT * FROM authors" ); // set query
         rowSet.execute(); // execute query

         // process query results
         ResultSetMetaData metaData = rowSet.getMetaData();
         int numberOfColumns = metaData.getColumnCount();
         System.out.println( "Authors Table of Books Database:" );

         // display rowset header
         for ( int i = 1; i <= numberOfColumns; i++ )
            System.out.printf( "%-8s\t", metaData.getColumnName( i ) );
         System.out.println();
        
         // display each row
         while ( rowSet.next() )
         {
            for ( int i = 1; i <= numberOfColumns; i++ )
               System.out.printf( "%-8s\t", rowSet.getObject( i ) );
            System.out.println();
         } // end while
      } // end try
      catch ( SQLException sqlException )
      {
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.