0

I am attempting to connect to a MYOB datafile using JDBC so that I can write a Java program to read some of the contents of that file.

As I am unfamiliar I have been looking at a variety of tutorials and they all fail with the error ClassNotFoundException in the same location leading me to believe I am missing a step that all the tutorials assume it is obvious.

The Error occurs when I try to run the following line (as per the current tutorial I am following:

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

The exact error is:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)

Could someone point me in the right direction I am currently using this tutorial but I am not sure why the Class cannot be found.

4
  • 1
    Have you added the library to the classpath? Commented Oct 24, 2013 at 10:27
  • You'll need to add mysqljdbc jar to your projects' buildpath. Commented Oct 24, 2013 at 10:28
  • 1
    what are you using for the develpment IDE aur Console? If you are using Console then add myslq.jar file into lib folder in java bin and if you are using IDE like Eclipse then follow the proper way to add jar file in it Commented Oct 24, 2013 at 10:40
  • You should show us how you include jdbc driver library in your project. Commented Oct 24, 2013 at 10:43

1 Answer 1

1

You are missing mysql connector jar file in your class path download from http://dev.mysql.com/downloads/connector/j/5.0.html

As the name suggests ClassNotFoundException in Java is a subclass of java.lang.Exception and Comes when Java Virtual Machine tries to load a particular class and doesn't found the requested class in classpath.

Another important point about this Exception is that, It is a checked Exception and you need to provide explicitly Exception handling while using methods which can possibly throw ClassNotFoundException in java either by using try-catch block or by using throws clause.

Oracle docs

public class ClassNotFoundException
 extends ReflectiveOperationException

Thrown when an application tries to load in a class through its string name using:

  • The forName method in class Class.
  • The findSystemClass method in class ClassLoader .
  • The loadClass method in class ClassLoader.

but no definition for the class with the specified name could be found.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok thanks this is not the only problem I've having but has resolved this issue, I figured I was missing a library but wasn't sure how to include one or where to find it, thanks.
@gRnt : You are welcome. Are there any more problems, post it. Happy to help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.