| ||||||||||||||
| ||||||||||||||
| ||||||||||||||
Using JDBC with DB2Example of JDBC applications with DB2 can be found in the directory /home/dbcourse/examples/jdbc/ on cps116. Please see the file README.txt for instructions. If you want to experiment with the code, you should make a copy in your home directory ("cp -r /home/dbcourse/examples/jdbc/ ~/") or on your own machine. Note that the file db2jcc4.jar is the DB2 JDBC driver (the directory /home/dbcourse/examples/jdbc/ contains a symbolic link to it). You will always need this driver on the machine where you are connecting to DB2 from. Another JDBC application example would be ra (link). Its code is not documented well, but does contain some more advanced examples such as obtaining metadata. The code resides in the directory /home/dbcourse/software/ra/. The example applications here illustrate how to make direct JDBC connections to the DB2 database. The JDBC driver and the connection URL might be database-specific, and you must provide user name and password for remote connections. Hence, this connection method is not ideal in situations where you want to make your application independent from the particular database you are connecting to. A solution is to use a JNDI data source, which hides all database- and connection-specific details. An example of using data sources can be found in our notes on the Tomcat web application server (link). Here is quick link to the JDBC API documentation online. For DB2-specific information, search for "Java application development for DB2" in DB2 Information Center; see notes on DB2 SQL (link) for URL. |
||||||||||||||
Last updated Mon Sep 22 21:29:20 EDT 2008 |