Java Tutorial - Java Script :
The
The JDBC-ODBC Bridge
Using this application with another database and driver would require changes to lines 16, 19, 75, and 77. Java DB requires a system property, derby.system.home, to be set to the location of the root folder where its databases are located. If this folder does not exist, Java DB will create it. The Java DB JDBC driver can be loaded with the following statement:Class.forName(“org.apache.derby.jdbc.EmbeddedDriver”);The Presidents application is split into the createDatabase() and readDatabase() methods whose functions are self-explanatory. Database creation employs the following database connection string for the DriverManager.getConnection(String) method in line 21:jdbc:derby:presidents;create=trueThis string follows the form “jdbc:derby:” followed by the database name, a semicolon, and the parameter “create=true”, which causes the database to be created if necessary. This string can include user and password parameters for a database that requires logon:jdbc:derby:presidents;user=dbuser;password=tortuga;create=trueMaking a connection to read from the database in line 79 is simpler:jdbc:derby:presidentsAfter you’ve made a successful connection to Java DB, reading and writing database records over JDBC follows the same process employed earlier today with JDBC-ODBC. SQL statements are written to create a database table, insert records into the table, and read those records. The SQL employed by Java DB has different record types than Access, MySQL, and other databases.Run the Presidents application the first time with “create” as the only argument to create the new database:java Presidents create If it is successful, the application outputs a message like the following:Database created in C:\Documents and Settings\Rogers\.database Run the application again with “read” as the argument to read and display the contents of the database:java Presidents readThe application produces the following output:Bill Clinton15 Old House Lane Chappaqua , NY 10514 (501) 370-8000George BushBox 79798Houston , TX 77279 (409) 260-9552George W. BushWhite House, 1600 Pennsylvania Ave. Washington , DC 20500 (202) 456-1414Jimmy CarterCarter Presidential Center1 Copenhill, Atlanta , GA 30307 (404) 727-7611The presence of Java DB is one of the most noteworthy improvements in Java 6. The availability of a relational database on all Java-equipped computers gives programmers a chance to take advantage of persistent data storag For more information on Java DB, visit the Sun Microsystems website at http://developers sun. com/prodtech/javadb.
Using this application with another database and driver would require changes to lines 16, 19, 75, and 77. Java DB requires a system property, derby.system.home, to be set to the location of the root folder where its databases are located. If this folder does not exist, Java DB will create it. The Java DB JDBC driver can be loaded with the following statement:
Class.forName(“org.apache.derby.jdbc.EmbeddedDriver”);
The Presidents application is split into the createDatabase() and readDatabase() methods whose functions are self-explanatory. Database creation employs the following database connection string for the DriverManager.getConnection(String) method in line 21:
jdbc:derby:presidents;create=true
This string follows the form “jdbc:derby:” followed by the database name, a semicolon, and the parameter “create=true”, which causes the database to be created if necessary. This string can include user and password parameters for a database that requires logon:
jdbc:derby:presidents;user=dbuser;password=tortuga;create=true
Making a connection to read from the database in line 79 is simpler:
jdbc:derby:presidents
After you’ve made a successful connection to Java DB, reading and writing database records over JDBC follows the same process employed earlier today with JDBC-ODBC. SQL statements are written to create a database table, insert records into the table, and read those records. The SQL employed by Java DB has different record types than Access, MySQL, and other databases.
Run the Presidents application the first time with “create” as the only argument to create the new database:
java Presidents create If it is successful, the application outputs a message like the following:
Database created in C:\Documents and Settings\Rogers\.database
Run the application again with “read” as the argument to read and display the contents of the database:
java Presidents read
The application produces the following output:
Bill Clinton
(501) 370-8000
George Bush
(409) 260-9552
George W. Bush
White House, 1600 Pennsylvania Ave.
(202) 456-1414
Jimmy Carter
Carter Presidential Center
1 Copenhill, Atlanta , GA 30307
(404) 727-7611
The presence of Java DB is one of the most noteworthy improvements in Java 6. The availability of a relational database on all Java-equipped computers gives programmers a chance to take advantage of persistent data storag For more information on Java DB, visit the Sun Microsystems website at http://developers sun. com/prodtech/javadb.
