• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DriverManager registerDriver not working

 
Alejandro Barrero
Ranch Hand
Posts: 355
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code:

Class dbDriverClass = loader.loadClass(jDataSourceClassTextField.getText());
Driver driver = (Driver) dbDriverClass.newInstance();
DriverManager.registerDriver(driver);
String url = "\"" + jURLTextField.getText() + "\"";
Enumeration<Driver> e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
Driver d = e.nextElement();
System.out.println(d.toString());
}
Driver d = DriverManager.getDriver(url);
String user = "\"" + jUserNameTextField.getText() + "\"";
String password = "\"" + jPasswordTextField.getText() + "\"";
Connection connection = DriverManager.getConnection(url, user, password);

DriverManager.registerDriver(Driver driver) is not working. I am loading the class org.hsqldb.jdbcDriver from the jar file
C:\Program Files\HSQLDB\hsqldb\lib\hsqldb.jar. and the url is
"jdbc:hsqldb:hsql://localhost/xdb"
but the commands
Driver d = DriverManager.getDriver(url);
Connection connection = DriverManager.getConnection(url, user, password);
throw SQLException with message "No suitable driver".
The enumeration doesn't find any registers drives either.

I do not know what I am doing wrong. Please help.

Alejandro Barrero
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alejandro,
Usually this problem is caused by the jar file not being in the classpath. Can you post the classpath?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic