Java Reference
In-Depth Information
Display 19.24
JSP Program to Create a Derby Database and Table (part 2 of 3)
13 try
14 {
15 Class.forName(driver).newInstance();
16 out.println("Loaded the embedded driver.<br>");
17 }
18 catch (Exception err)
19 {
20 out.println(
"Unable to load the embedded driver.</body></html>");
21 return;
22 }
A return statement will
terminate the JSP program.
23 String dbName = "BookDatabase";
24 Connection conn = null ;
25 try
26 {
27 out.println(
"Connecting to and creating the database...<br />");
28 conn = DriverManager.getConnection(protocol + dbName +
";create=true");
29 out.println("Connected.<br />");
30 Statement s = conn.createStatement();
31 s.execute("CREATE TABLE names" +
32 "(author varchar(50), author_id int , url varchar(80))");
33 out.println("Created 'names' table.<br />");
34 out.println("Inserting authors.<br />");
35 s.execute("INSERT INTO names " +
36 "VALUES ('Adams, Douglas', 1, 'http://www.douglasadams.com')");
37 s.execute("INSERT INTO names " +
38 "VALUES ('Simmons, Dan', 2, 'http://www.dansimmons.com')");
39 s.execute("INSERT INTO names " +
40 "VALUES ('Stephenson, Neal', 3," +
"'http://www.nealstephenson.com')");
41 out.println("Authors inserted.<br />");
42 conn.close();
43 }
44 catch (Exception err)
45 {
46 out.println("SQL error.<br />");
47 }
48 %>
49 </body>
50 </html>
Search WWH ::




Custom Search