/** * Created by lifei on 16/7/14. */ publicclassDerby{ publicstaticvoidmain(String[] args){ try { Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:derby:memory:myDB;create=true");
Statement st = conn.createStatement(); st.execute("create table test2 (id int, name varchar(20))"); st.execute("insert into test2 values(1,'sinboy')"); st.execute("insert into test2 values(2,'Tom')");
ResultSet rs = st.executeQuery("select * from test2"); // ResultSet rs = st.executeQuery("SELECT * from test2 where name REGEXP '^T'");//不支持 while (rs.next()) { System.out.println("id:" + rs.getInt(1) + " name:" + rs.getString(2)); } rs.close(); st.close(); conn.commit(); conn.close(); } catch (Exception e) { e.printStackTrace(); } } }