• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Driver loading

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I got a question as follows:

Which of the following will not cause a JDBC driver to be loaded and registered with the DriverManager?
A. Class.forName(driverString);
B. new DriverClass();
C. Include driver name in jdbc.drivers system property
D. None of the above

I though the answer is B because I did not find any DriverClass API. However, I was told that the anwser is D. Can someone explain it to me?
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Answer is A
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a JDBC Driver Class is loaded by the ClassLoader, it is required (via a static code block) to register itself with the DriverManager. A and B both accomplish this. C is a special mechanism for moving the Driver dclaration outside the code, but doesn't appear to used as often as A.

Therefore all 3 end up with the Driver class being loaded and registered with the DriverManager.

I'm hoping this isn't homework, can I ask where the question is from?
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

This is provided by JGuru and in Sun's Quizzes. Thank you for your help.
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

In your last post, you said "When a JDBC Driver Class is loaded by the ClassLoader, it is required (via a static code block) to register itself with the DriverManager".

Where is this static code block? Is it part of the Driver Class? And what is it?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any basic Java book should have information on static and instance blocks. We're getting close to the point where you should ask a new question in the JiG(beginners) forum, but try this code:



When the Class is loaded (ie the first time a ClassLoader 'sees' this Class), it calls the static block once (and only ever once!) before it does anything else with the Class. In Drivers they register themselves with the DriverManager.

Hope this gets you started.
 
reply
    Bookmark Topic Watch Topic
  • New Topic