+3 votes
in Programming Languages by (11.1k points)

When I try to run Java+MySQL code in Netbeans, I am getting the following error...

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at ConnectAndAccess.connectDB(ConnectAndAccess.java:17)
    at ConnectAndAccess.main(ConnectAndAccess.java:62)
BUILD SUCCESSFUL (total time: 0 seconds)

 

 

1 Answer

0 votes
by (11.1k points)

You need to add JDBC MySQL driver to Netbeans. From menu bar, select Run option and do the followings to add MySQL JDBC driver to Netbeans.

Run -> Set project configuration -> select Libraries under Categories -> Add Library -> select MySQL JDBC Driver -> Click OK (keep Build projects on Classpath checked)

...