0

Added mysql-connector-java-5.1.22-bin.jar to the library. Created a class, imported all the java.sql packages. Have public static void main and a constructor. In the main, added the line ...

DriverManager.getConnection("jdbc:mysql://localhost/lookups", "root", "dummyPWd")

It does not throw an exception and I can do stuff with the database. Add the same line to the Constructor and I get an error:

No suitable driver found ...

Why would it work in main method but not inside a class constructor?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332

1 Answers1

-2

Try to use a DriverShim class like this one: http://www.kfu.com/~nsayer/Java/dyn-jdbc.html

So you don't need to put the JDBC driver in your classpath.

Works like a charm.

Balazs Gunics
  • 2,017
  • 2
  • 17
  • 24
  • 1
    That just defers the problem. The driver JAR still has to be somewhere. There's no evidence here that he needs runtime driver selection. – user207421 Apr 23 '14 at 23:44