wood burning stoves 2.0*
The moose likes JDBC and the fly likes confirm JDBC Driver registration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "confirm JDBC Driver registration" Watch "confirm JDBC Driver registration" New topic
Author

confirm JDBC Driver registration

Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
when we register a JDBC driver with java, say by doing Class.forName(..), how can we make sure tht the driver is registered? apart from checking for any exception? or do we assume that if no exception is thrown, then the driver registered successfully?

in other words, is there a way to find out all the drivers registered with a system?
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

Drivers register themselves with the DriverManager when loaded. This registration is mandated by JDBC specification and is done thru a static block of code that each driver implementation has. You can get the list of all registered drivers as DriverManager.getDrivers()
sarah khan
Greenhorn

Joined: Apr 09, 2005
Posts: 2
what's mysql 's driver name is it for example


mysql-connector-java-3.1.7-bin.jar

I am trying to connect to mysql and I have the above mentioned driver installed and am trying to connect to it I get no exceptions in registering it!!! but getting null exceptions when try to connect to it??? I tried the
System.out.println(DriverManager.getDrivers());

and it printed
java.util.Vector$1@b753f8

some sort of address (does not tell me a whole lot???)

here's the exact code I have to connect:

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String tURLString = "jdbc:mysql://localhost/empdb?user=root&password=admin";
boolean tStillTrying = true;
int tNumberOfTries = 0;
while (tStillTrying) {
try {
System.out.println(DriverManager.getDrivers());
iConnection = DriverManager.getConnection(tURLString, "", "");
tStillTrying = false;
}
catch (Exception rException) {
tNumberOfTries++;
tStillTrying = (tNumberOfTries > 20);
}
}
if ( iConnection == null )
System.out.println("iConnection is null");
else
System.out.println("got connected to the database");
anson cai
Greenhorn

Joined: Apr 11, 2005
Posts: 2
Did you try?
...
String tURLString = "jdbc:mysql://localhost/empdb";
...
iConnection = DriverManager.getConnection(tURLString, "root", "admin");
...

or maybe your password and usrid is not matched?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confirm JDBC Driver registration
 
Similar Threads
NoClassDefFoundError
Database Connectivity
Loading JDBC driver
DriverManager iterating through driver lists, will it create an overhead ?
need help on dynamic loading of jdbc driver