Code example for ResultSetMetaData

Methods: getColumnCountgetColumnName

0
 
    @Test 
    public void metaData() throws SQLException { 
        PreparedStatement prep = conn.prepareStatement("select ? as col1, ? as col2, ? as delta;");
        ResultSetMetaData meta = prep.getMetaData();
        assertEquals(meta.getColumnCount(), 3);
        assertEquals(meta.getColumnName(1), "col1");
        assertEquals(meta.getColumnName(2), "col2");
        assertEquals(meta.getColumnName(3), "delta");
        /*assertEquals(meta.getColumnType(1), Types.INTEGER); 
        assertEquals(meta.getColumnType(2), Types.INTEGER); 
        assertEquals(meta.getColumnType(3), Types.INTEGER);*/ 
 
        meta = prep.executeQuery().getMetaData();
        assertEquals(meta.getColumnCount(), 3);
        prep.close();
    } 
 
    @Test 
    public void date1() throws SQLException { 
Stop searching for code, let great code find you!  Add Codota to your java IDE