Starts up the Derby engine Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); Creates and connects to a database Connection conn = DriverManager.getConnection("jdbc:derby:" + dbName + ";create=true"); // 若要自行手動控制transaction, 要將JDBC中預設的autocommit功能關掉. conn.setAutoCommit(false); Creates a table // 可針對該資料庫重複使用的Statement物件 Statement stmt = conn.createStatement(); // 建立名為location的資料表 stmt.execute("CREATE TABLE location(num int, addr varchar(40))"); Inserts data // 當重覆執行SQL敘述時, 建議使用PreparedSstatement(可以不需要每次都recompileSQL敘述) PreparedStatement pStmt = conn.prepareStatement("INSERT INTO location VALUES(?, ?)"); pStmt.setInt(1, 1956); pStmt.setString(2, "Min-Sheng East Road"); pStmt.executeUpdate(); Updates data PreparedStatement psUpdate = conn.prepareStatement("UPDATE location SET num=?, addr=? where num=?"); psUpdate.setInt(1, 300); psUpdate.setString(2, "Cheng-Guong ...