One should check with the DBMS administrator for advice about
which driver to load for the particular DBMS in use. One can find information about JDBC drivers at:
http://industry.java.sun.com/products/jdbc/drivers.
A typical snippet of Java code loading a JDBC driver is the following:
// Dynamically loads a class called OracleDriver which is in
// the file classes12.zip
// The environment variable CLASSPATH must be set to include
// the directory in which the file classes12.zip exists.
Class.forName("oracle.jdbc.driver.OracleDriver");
Once the driver is loaded, the program can establish a connection to the database. The Connection class
is available by importing the java.sql.* package. To create a Connection, the program needs a user
name and a password, just as a person would. Here is a typical snippet of code to create a Connection object
for the database:
import java.sql.*;
...
// The url means: JDBC driver: Oracle's version:
// "thin" driver type, located on cpu reddwarf,
// in domain cs.rit.edu, default port number 1521,
// database sid "odb"
String url="jdbc:oracle:thin:@reddwarf.cs.rit.edu:1521:odb";
// Create a connection object
162 DATABASE [CHAP. 8
// Note that, by default, a connection opens in
// auto-commit mode
// (every statement is committed individually).
Pages:
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446