| 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: 345
|
|
|
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?
|
 |
 |
|
|
subject: confirm JDBC Driver registration
|
|
|