The response for this is too simple.
The JDBC driver needs to be registered in the DriverManager class, for make the registration of the driver the runtime needs to call the implementation driver class this class can be the SQLServerDriver or the OracleDriver class, when the java runtime load this class a static block of code is executed and this execution of code make the registration of the driver in the DriverManager class.
Why we need to register a driver well if you do not register the driver, you are not able to get a connection from the DriverManager because the driver manager does not know anything about the database driver and does not have a register of the database driver.
In the java doc for the DriverManager class you can see the following methods that help to register a database driver:
deregisterDriver(Driver driver)
registerDriver(Driver driver)
Javadoc for Driver Manager: http://docs.oracle.com/javase/7/docs/api/
Note: for new drivers this behaviors is not more needed because the registration of the class is executed by a service registration in the META-INF files if you want more information about that, you can find in internet "Service Provider implementations in Java".
No comments:
Post a Comment