14-12-2012, 06:49 PM
JDBC - Database Connections
JDBC - Database Connections.docx (Size: 21.68 KB / Downloads: 21)
Import JDBC Packages:
The Import statements tell the Java compiler where to find the classes you reference in your code and are placed at the very beginning of your source code.
To use the standard JDBC package, which allows you to select, insert, update, and delete data in SQL tables, add the following imports to your source code:
Register JDBC Driver:
You must register the your driver in your program before you use it. Registering the driver is the process by which the Oracle driver's class file is loaded into memory so it can be utilized as an implementation of the JDBC interfaces.
You need to do this registration only once in your program. You can register a driver in one of two ways.
Database URL Formulation:
After you've loaded the driver, you can establish a connection using theDriverManager.getConnection() method. For easy reference, let me list the three overloaded DriverManager.getConnection() methods:
1. getConnection(String url)
2. getConnection(String url, Properties prop)
3. getConnection(String url, String user, String password)
Here each form requires a database URL. A database URL is an address that points to your database.
Formulating a database URL is where most of the problems associated with establishing a connection occur.
Following table lists down popular JDBC driver names and database URL.