You must provide the code to register your installed driver with your program.
You do this with the static registerDriver( )
method of the JDBC DriverManager class.
DriverManager.registerDriver(
new oracle.jdbc.driver.OracleDriver( ) );
The DriverManager
class is used to open a connection to a database via a JDBC driver, which must be registered with the DriverManager
.
DriverManager
chooses from a given list of available drivers to suit the explicit type of database connection.
Three major methods of this class are
public static void registerDriver(Driver driver) throws SQLException
Registers the given driver with the DriverManager
.
A newly-loaded driver class should call the method registerDriver
to make itself known to the DriverManager
.
public static Connection getConnection (String driver, String userid, String password) throws SQLException
Attempts to establish a connection to the given database URL.
The DriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.
public static Driver getDriver(String url) throws SQLException
Attempts to locate a driver that understands the given URL.
The DriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.
Because you are using one of Oracle's JDBC drivers, you declare a specific driver name string to registerDriver( )
.
You register the driver only once in your Java application.