java JDBC

        String driver = "org.apache.derby.jdbc.EmbeddedDriver";

        String dbURL = "jdbc:derby:EmbeddedDB;create=true";

        try{

            Class.forName(driver);

            Connection conn = DriverManager.getConnection(dbURL);

            Statement st = conn.createStatement();

            st.execute("CREATE table foo(ID INT NOT NULL, NAME VARCHAR(30))");

            st.executeUpdate("insert into foo(ID,NAME) values(1,'Tu Chuanbin')");

            ResultSet rs = st.executeQuery("select * from foo");

            while(rs.next()){

                int id = rs.getInt(1);

                String name = rs.getString(2);

            }

        }catch(Exception ex){

            ex.printStackTrace();

        }

 

你可能感兴趣的:(java)