Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confirm JDBC Driver registration

 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try?
...
String tURLString = "jdbc:mysql://localhost/empdb";
...
iConnection = DriverManager.getConnection(tURLString, "root", "admin");
...

or maybe your password and usrid is not matched?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic