This looks like a repeat of a previous thread, but I still haven't cracked it.
I'm doing everything on a single Windows XP pc, so no servers or clever stuff involved.
I blew the space on MS Access so I'm attempting to return to plan A of using MySQL.

Java DB
Java SE development Kit 6
Java Runtime Environment 6
JCreatorLE 3.10
MySQL Server 5.1
MySQL Workbench 5.1 OSS
MySQL Workbench 5.2 CE

I put mysql-connector-java-5.1.13-bin.jar in C:\Program Files\Java\jre6\lib\ext

I put "CLASSPATH .;C:\Program Files\Java\jre6\lib\ext\mysql-connector-java-5.1.13-bin.jar" in system variables.

My source includes:

import java.sql.*;

               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
           catch (Exception e)
               System.err.println (e + "  Cannot get driver");
               System.out.println("MySQL JDBC driver loaded ok.");

               String url = "jdbc:mysql://";
               PAFConn = DriverManager.getConnection (url);
               System.out.println ("Database connection established");
           catch (Exception e)
               System.err.println (e + "Cannot connect to database server");

The code may be a bit flaky, but I'm brand new to this.
The log says
"java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Cannot get driver"
so we fell down at the first hurdle.

I thought I'd followed all the on-line advice I could find, but still I'm not getting through. I was fine(ish) before with MS Access, so clearly I've missed something on MySQL.

All suggestions gratefully received. I'm flummoxed!

Recommended Answers

All 3 Replies

First, remove that jar file from the ext directory, it does not belong there, and you would have to do it again with every upgrade to Java so it wouldn't be worth it anyway. Then, you can forget about the CLASSPATH environment variable your IDE won't use it to run your project, and, if you later create a jar, it wouldn't be used either. Add the jar as a library in the project settings for your project within your ide.

what is your compiler so i can help in adding this jar file which is the problem

commented: The "compiler" has nothing to do with it. -2
commented: Need to do more reading on JDBC my friend. Your approach is wrong -3

The "compiler" doesn't matter, the IDE, or more correctly the development environment does and IDE stands for Integrated Development Environment. All the compilers handle the classpath in the same manner as this is part of the standard. It can't even call itself a compiler if it doesn't (IOW). It's the IDEs that have varying ways of designated the libraries to include on the classpath and 99% of the time it has to do with project properties/settings, as already mentioned.

Let the OP read the IDE doumentation with that in mind and do it, there is nothing else that needs to be added in that respect, and the compiler definately has nothing to do with it (especially since this is a runtime error and not a compile time error).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.