Java Reference
In-Depth Information
LISTING 18.3
Continued
10: system = home + File.separatorChar + “.database”;
11: System.setProperty(“derby.system.home”, system);
12: }
13:
14: public void createDatabase() {
15: // create the database
16: String data = “jdbc:derby:presidents;create=true”;
17: try {
18: // load the driver
19: Class.forName(“org.apache.derby.jdbc.EmbeddedDriver”);
20: // create the connection
21: Connection conn = DriverManager.getConnection(data);
22: Statement st = conn.createStatement();
23: // create the contacts table
24: int result = st.executeUpdate(
25: “CREATE TABLE contacts (“
26: + “dex INTEGER NOT NULL PRIMARY KEY “
27: + “GENERATED ALWAYS AS identity “
28: + “(START WITH 1, INCREMENT BY 1), “
29: + “name VARCHAR(40), “
30: + “address1 VARCHAR(40), “
31: + “address2 VARCHAR(40), “
32: + “phone VARCHAR(20), “
33: + “email VARCHAR(40))”);
34: // insert four records into the new table
35: result = st.executeUpdate(
36: “INSERT INTO contacts (name, address1, address2, “
37: + “phone, email) VALUES(“
38: + “'Jimmy Carter', “
39: + “'Carter Presidential Center', “
40: + “'1 Copenhill, Atlanta, GA 30307', “
41: + “'(404) 727-7611', “
42: + “'carterweb@emory.edu')”);
43: result = st.executeUpdate(
44: “INSERT INTO contacts (name, address1, address2, “
45: + “phone, email) VALUES(“
46: + “'George Bush', “
47: + “'Box 79798', “
48: + “'Houston, TX 77279', “
49: + “'(409) 260-9552', “
50: + “'library@bush.nara.gov')”);
51: result = st.executeUpdate(
52: “INSERT INTO contacts (name, address1, address2, “
53: + “phone, email) VALUES(“
54: + “'Bill Clinton', “
55: + “'15 Old House Lane', “
56: + “'Chappaqua, NY 10514', “
57: + “'(501) 370-8000', “
58: + “'info@clintonpresidentialcenter.com')”);
Search WWH ::




Custom Search