0

I have set of DB connection statements in my java file which takes the driver name, url, username and password from my property file and then try to make a connection. But I am keep getting error exactly in this try block . My code is

try {
    Class.forName(properties.getProperty("DB2.database.driver"));
} catch (Exception e) {
    System.err.println("Unable to locate database driver:" + e);             
    return null;
}

The error message is

Unable to locate database `driver:java.lang.ClassNotFoundException:

May i know why it is keep getting this error?

philipjkim
  • 3,999
  • 7
  • 35
  • 48
Sankar
  • 11
  • 2
  • Does this answer your question? [ClassNotFoundException when using JDBC driver for DB2](https://stackoverflow.com/questions/17153477/classnotfoundexception-when-using-jdbc-driver-for-db2) – Petr Aleksandrov Dec 16 '19 at 21:22
  • Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Include the *complete* stacktrace and error message. As written, the problem could be a number of things, – Stephen C Dec 17 '19 at 02:22
  • @PetrAleksandrov . Thanks. your suggestion worked. – Sankar Dec 19 '19 at 16:29
  • @StephenC The problem was because of missing DB2 jar. Thanks though. – Sankar Dec 19 '19 at 16:31
  • @ArvindKumarAvinash It worked after i added the required jar in classpath. Thanks. – Sankar Dec 19 '19 at 16:32

0 Answers0