About Question enthuware.ocpjp.v8.2.1375 :
Moderator: admin
-
- Posts: 10
- Joined: Mon Aug 18, 2014 5:25 am
- Contact:
About Question enthuware.ocpjp.v8.2.1375 :
When Connection c = DriverManager.getConnection("jdbc:fandu://localhost:1234/myDB", "user", "pwd"); doesn't load the driver,
at what point in time is the driver actually loaded?
at what point in time is the driver actually loaded?
Online
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
As per http://docs.oracle.com/javase/tutorial/ ... cting.html:
HTH,
Paul.
Further on the same page it also says,When this class first attempts to establish a connection, it automatically loads any JDBC 4.0 drivers found within the class path.
As per https://docs.oracle.com/javase/7/docs/a ... nager.html,Any JDBC 4.0 drivers that are found in your class path are automatically loaded.
So basically DriverManager.getConnection will probably cause the driver to load. But it is not a "required" thing for loading a driver. The driver could be loaded even before anyone calls getConnection.As part of its initialization, the DriverManager class will attempt to load the driver classes referenced in the "jdbc.drivers" system property. This allows a user to customize the JDBC Drivers used by their applications. For example in your ~/.hotjava/properties file you might specify:
jdbc.drivers=foo.bah.Driver:wombat.sql.Driver:bad.taste.ourDriver
The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:
my.sql.Driver
Applications no longer need to explictly load JDBC drivers using Class.forName(). Existing programs which currently load JDBC drivers using Class.forName() will continue to work without modification.
When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Mon Aug 18, 2014 5:25 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
Paul,
the devil is in the details! Thank's for explaining this clearly.
the devil is in the details! Thank's for explaining this clearly.
-
- Posts: 13
- Joined: Sun Mar 27, 2016 1:10 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
Shouldn't the question mention that it is about a JDBC 4.0 driver? Or can I assume all question on the exam are about 4.0?
Online
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
Yes, unless explicitly mentioned you should assume JDBC 4.0.
If you like our products and services, please help us by posting your review here.
-
- Posts: 197
- Joined: Mon Jun 20, 2016 5:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
Hi
Here it says
Does it mean that you have to call DriverManager.getConnection to load the drivers, thus answer 1 shall be correct one?
Please check on referred page.
Here it says
http://docs.oracle.com/javase/tutorial/ ... cting.htmlDriverManager: This fully implemented class connects an application to a data source, which is specified by a database URL. When this class first attempts to establish a connection, it automatically loads any JDBC 4.0 drivers found within the class path. Note that your application must manually load any JDBC drivers prior to version 4.0.
Does it mean that you have to call DriverManager.getConnection to load the drivers, thus answer 1 shall be correct one?
Yes, but after you call DriverManager.getConnection only.Any JDBC 4.0 drivers that are found in your class path are automatically loaded.
Please check on referred page.
Online
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
Yes, DriverManager does load the drivers. But that may not necessarily be the only way to load the drivers. Nowhere does it say that only DriverManager can load the drivers.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Sun Feb 07, 2021 6:30 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
so if the question was
Which of the following lines of code can get the driver loaded?
instead of
Which of the following lines of code is/are required to get the driver loaded?
then A would have been correct?
Which of the following lines of code can get the driver loaded?
instead of
Which of the following lines of code is/are required to get the driver loaded?
then A would have been correct?
Online
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1375 :
Yes, correct.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 32 guests