Slide 12.4: Importing packages Slide 12.6: 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
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.
JDBC technology exploits the advantages of Internet-standard URLs to identify database connections.
|
public static Driver getDriver(String url) throws SQLException
DriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.
registerDriver( )
and register the driver only once in your Java application.