
import java.sql.*;

public class DERBYNEW {
    
    public static void main(String[] args) throws Exception {
        ResultSet rs;
        PreparedStatement pSt;
        ResultSetMetaData rsmd;
        String []expColNames;
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        Connection conn =
                (Connection) DriverManager.getConnection("jdbc:derby:testdb;create=true");
        Statement st = conn.createStatement();
        
        st.executeUpdate(
                "create table bt1 (i int, c char(5), de decimal(4, 1))");

        st.executeUpdate(
                " insert into bt1 values (1, 'one', null), (2, " + "'two', 22.2), (3, 'three', null)," + "  (7, 'seven', null), (8, 'eight', 2.8), (9, " + "'nine', null), (3, 'trois', 21.2)");

        st.executeUpdate(
                " insert into bt1 (i) values 10, 11, 12, 13, 14, 15, " + "16, 17, 18, 19, 20");

        st.executeUpdate(" update bt1 set c = cast (i as char(5)) where i >= 10");

        st.executeUpdate(" update bt1 set de = cast (i/2.8 as decimal(4,1)) " + "where i >= 10 and 2 * (cast (i as double) / 2.0) - " + "(i / 2) = i / 2");

        pSt = conn.prepareStatement("select * from bt1 where i in (?, ?, 1)");
        rs = st.executeQuery(
                "values (3, cast (null as int))");

        rs.next();
        rsmd = rs.getMetaData();
        for (int i = 1;
                i <= rsmd.getColumnCount(); i++) {
            pSt.setObject(i, rs.getObject(i));
        }
        rs = pSt.executeQuery();
       
    }
    
}

