Analysis should be performed on the programming process to establish a JDBC connection and includes
- importing the JDBC packages using import statements in the Java program to import the related Java classes
- registering the JDBC driver to instruct the JVM to load the driver into memory so JDBC requests can be performed
- creating database URL notation by creating a properly formatted URL address so the database can connect, such as in the following example:
getConnection(String url)
getConnection(String url, String user, String password)
- creating a connection object by programming a call to the DriverManager object’s getConnection() method to establish the actual database connection. The most commonly used form of getConnection() requires you to pass a database URL, a username, and a password
- establishing a port-addressing connection, such as in the following summary and complete examples:
(Summary)
jdbc:oracle:thin:@jdoe:1511:EMP URL Connection: DriverManager.getConnection(String url, Properties info);
(Complete)
import java.util.*;
String URL = "jdbc:oracle:thin:@jdoe:1511:EMP";
Properties info = new Properties( );
info.put( "user", "username" );
info.put( "password", "password" );
Connection conn = DriverManager.getConnection(URL, info);