Previously wrote an example of connecting MySQL in a JSP page
When connecting Derby, just the connection attribute of JDBC has changed, and it is small.
The Derby database is different from mysql that it has two ways: Embbed and Net Server
It is only used in the form of the first EMBBED here, and the second type has not been tried.
System Operation Environment: WinXP JDK1.4.2 Tomcat Cloudscape10.0
The following is a specific web code:
Try {class.Forname ("org.apache.derby.jdbc.embeddedddriver"); // Derby database Embbed driver name Out.println ("Success Loading Derby Driver!");} catch (Exception E) {Out.print ("Error Loading Derby Driver!"); E.PrintStackTrace ();
Try {Properties Properties = New Properties (); Properties.put ("Create", "True"); // New Database Properties.put ("User", "App"); // User Name Properties.put ("Password "" APP "); // password
properties.put ( "retreiveMessagesFromServerOnGetMessage", "true"); // Get a connection Connection connect = DriverManager.getConnection (databaseURL, properties); out.print ( "! Success connect derby server");
Statement s = connect.createstatement ();
S.Execute ("Create Table Jimmydb2 (" Created Table Jimmydb2 "); S.EXECUTE (" Insert Into Jimmydb2 Values (1956, 'Webster St.') "); Out.println (" Inserted 1956 Webster "); S.Execute (" INSERT INTO JIMMYDB2 VALUES); OUT.PRINTLN ("INSERTED 1910 Union"); S.Execute "Update Jimmydb2 Set Num = 180, AddR = 'Grand Ave.' Where Num = 1956"); Out.Println ("Updated 1956 Webster to 180 Grand"; S.Execute ("Update Jimmydb2 Set Num = 300, AddR = 'Lakeshore Ave.' Where Num = 180 "); Out.Println (" Updated 180 Grand To 300 Lakeshore);
ResultSet RS = S.ExecuteQuery ("SELECT NUM, ADDR from Jimmydb2 Order By Num");
While (Rs.Next ()) {Out.println (Rs.Getint (1)); Out.Println (rs.getstring (2));}
} Catch (exception e) {OUT.PRINT ("Error!"); E.PrintStackTrace ();}
%>
body> html>