Code example for ResultSet

Methods: close, getMetaData, next

0
 
        st2.close();
 
        st3 = conn.createStatement();
        rs = st3.executeQuery(select);
        assertTrue(rs.next());
        rsmd2 = rs.getMetaData();
 
        assertNotNull(rsmd2);
        assertEquals(precicisionReal, rsmd2.getPrecision(4));
        assertEquals(precisionNum,rsmd2.getPrecision(3));
        assertTrue(rsmd2.getPrecision(2) > 0);
        assertTrue(rsmd2.getPrecision(1) > 0);
 
        // non numeric field 
        try { 
            rsmd.getPrecision(3);
        } catch (SQLException e1) {
            System.out.println("ResultSetMetaDataTest.testGetPrecision()"+e1.getMessage());
            e1.printStackTrace();
        } 
 
 
        try { 
            rsmd.getPrecision(0);
            fail("SQLException is not thrown"); 
        } catch (SQLException e) {
            // expected 
        } 
        try { 
            rsmd.getPrecision(5);
            fail("SQLException is not thrown"); 
        } catch (SQLException e) {
            // expected 
        } 
 
        try { 
            rs.close();
            rsmd.getPrecision(1);
            fail("Exception expected"); 
        } catch (SQLException e) {
            //ok 
        }