The moose likes JDBC and Relational Databases and the fly likes How to get the driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to get the driver" Watch "How to get the driver" New topic
Author

How to get the driver

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9056
    
  12
I have always used a statement like

to get the JDBC driver.

Why don't we just import it with an import statement?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63052
    
  69

An import statement merely makes a class available to the compilation unit at compile time. The Class.forName() causes the class loader to physically find the class and load it into the JVM at run-time (where the driver manager will find and hook up to it).
[ April 13, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by Marilyn de Queiroz:
I have always used a statement like

to get the JDBC driver.

Why don't we just import it with an import statement?

Have a read of this. It's designed to allow flexibility for interchanging drivers, but you could use the import if you wanted to and skip all the classloader stuff.
Jamie
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9056
    
  12
Thank you. That was helpful.
 
Consider Paul's rocket mass heater.
 
subject: How to get the driver
 
It's not a secret anymore!