• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a driver class and why should it be registered?

 
Gautham Muralidharan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The very first step in connecting a mysql database in java is to register the driver class using the following code.



What is a driver class?
What is the need to register a driver class?
Why don't we register any driver classes in our regular java programs (which don't connect to a database)?

Thanks in advance.
 
Henry Wong
author
Marshal
Pie
Posts: 22124
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, simply, the JDBC driver is the implementation that know how to get to the particular database.

For example, let's say you want to use JoeBob Database (tm). First step, obviously, is to setup the database. Second step, get the JoeBob database implementation driver from Joe Bob corporation. This will most likely be a jar file, that you will need to add to the class path.

And finally, if you are using an old implementation, you will need to add a line of code that will register with the JDBC manager, on how to find the drivers to get to JoeBob database (hence, your question). Also note, with newer versions of Java, there is an option in the jar file that will automatically load the driver, so that line would no longer be needed.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic