Slide 14.25: Importing packages Slide 14.27: Opening a connection to a database Home |
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
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
DriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.
public static Driver getDriver(String url) throws SQLException
DriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.
registerDriver( )
.
You register the driver only once in your Java application.