I am trying to connect Java code to mySQL. Here is the error I received. I do not understand why the driver was not found, since I installed the jar connector in the classpath.
Class Not Found Exception:
No suitable driver found for jdbc:mysql://localhost/hpdata?user=root&password=12
3456
Exception in thread "main" java.lang.NullPointerException
at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.open(FeatureSpe
cRDB.java:122)
at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.<init>(FeatureS
pecRDB.java:66)
at edu.indiana.iucbrf.domain.componentfactory.RDBComponentFactory.constr
uctProblemFeatureSpecCollection(RDBComponentFactory.java:112)
at edu.indiana.iucbrf.domain.Domain.<init>(Domain.java:239)
at edu.indiana.iucbrf.domain.Domain.<init>(Domain.java:197)
at edu.indiana.iucbrf.examples.honeypotRDBTemplate.HDomainRDB.<in
it>(HDomainRDB.java:56)
at edu.indiana.iucbrf.examples.hRDBTemplate.HSystemRDB.set
upDomain(HSystemRDB.java:198)
at edu.indiana.iucbrf.examples.hRDBTemplate.HSystemRDB.<in
it>(HSystemRDB.java:131)
at edu.indiana.iucbrf.examples.hRDBTemplate.HTestClassRDB.
main(HTestClassRDB.java:65)
Here is my code:
private static void flush() {
Class.forName("com.mysql.jdbc.Driver").newInstance();
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hpdata?user=root&password=123456");
} catch (Exception e) {
System.out.println("Class Not Found Exception:");
System.out.println(e.getMessage());
}
source
share