Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Java / MySQL question?

This is my code

public class Main {

public static void main(String[] args) {

Connection myConnection;

System.out.println("Sample db connectivity using MySQL and netbeans");

try{

Class.forName("com.mysql.jdbc.Driver");

myConnection=DriverManager.getConnection(

"jdbc:mysql://localhost:3306/sample","nbenavidez","password"

);

}

catch(Exception e){

System.out.println("Failed to get connection - This is BSSSSS");

e.printStackTrace();

}

}

}

the error :

Failed to get connection - This is BSSSSS

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:169)

at dbsample.Main.main(Main.java:28)

Update:

I have the connector in place (the jar file) and it does compile fine also

2 Answers

Relevance
  • Mike S
    Lv 6
    1 decade ago
    Favorite Answer

    make sure that you add the driver path into -cp for runtime.

  • Anonymous
    1 decade ago

    edede

Still have questions? Get your answers by asking now.