permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes ClassNotFoundException Mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ClassNotFoundException Mysql" Watch "ClassNotFoundException Mysql" New topic

ClassNotFoundException Mysql

Vince Black

Joined: Oct 16, 2003
Posts: 4
hi !
I have a problem :
The Error Message is ->
An exception has been intercepted
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(
at Database.main(
My Code is :
import java.sql.*;
import java.util.Properties;
public class Database
public static void main( String args[] )
// Register MySQL driver

// Open a properties file where connection info is stored
FileInputStream infile = new FileInputStream( "" );
Properties props = new Properties();
// Connection info for MySQL
String dbserver = props.getProperty("dbserver", "localhost");
String dbname = props.getProperty("dbname", "test");
String user = props.getProperty("user", "root");
String password = props.getProperty("password", "");
String cs = "jdbc:mysql://"+dbserver+"/"+dbname+"?user="+user+"&password="+password;
// The SQL statement to execute
String sql = "SELECT * FROM daten";
// Open a connection to the database
Connection conn = DriverManager.getConnection(cs);
Statement stat = conn.createStatement();
// Execute the query
ResultSet rs = stat.executeQuery(sql);
// Display results
while (
// Close everyting
catch (Exception ex)
System.out.println( "An exception has been intercepted" );
i dont know the Problem i am a Newbie
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

According to the installation documentation, you have to put the MySQL Connector/J jar file in your classpath.

[How To Ask Questions On JavaRanch]
Vince Black

Joined: Oct 16, 2003
Posts: 4
i dont know how can i make it i am a real Java Newbie .
I dont unterstand how to make it .
so can you help me ..
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Again, the DOCUMENTATION states:

Setting the CLASSPATH (For Standalone Use)
Once you have un-archived the distribution archive, you can install the driver in one of two ways: Either copy the "com" and "org" subdirectories and all of their contents to anywhere you like, and put the directory holding the "com" and "org" subdirectories in your classpath, or put mysql-connector-java-[version]-bin.jar in your classpath, either by adding the FULL path to it to your CLASSPATH enviornment variable, or by copying the .jar file to $JAVA_HOME/jre/lib/ext. If you are going to use the driver with the JDBC DriverManager, you would use "com.mysql.jdbc.Driver" as the class that implements java.sql.Driver.
Example 2.1. Setting the CLASSPATH Under UNIX
The following command works for 'csh' under UNIX:
$ setenv CLASSPATH /path/to/mysql-connector-java-[version]-bin.jar:$CLASSPATH
The above command can be added to the appropriate startup file for the login shell to make MySQL Connector/J available to all Java applications.
Example 2.2. Setting the CLASSPATH Under Microsoft Windows 9X
The following is an example of setting the CLASSPATH under Microsoft Windows 95, 98, ME:
C:\> set
This command can be added as the last line in AUTOEXEC.BAT. If this is done the MySQL Connector/J driver will be made available to all Java applications that run on the Windows 9x system. This setting will require the computer to be rebooted before the changes will take effect.
Tomi M�ntyl�

Joined: Dec 30, 2005
Posts: 1
In JCreator, for example, you seem to be best off by setting JCreator class path separately. (You can find the instructions on how to do this in JCreator by hitting F1).

I set the Creator/J to the system classpath on WinXP, but the code didn't work. I haven't made a jar yet to run without JCreator, so I don't know what happens with the class paths then.

This just seems to show that the class path can lie about anywhere.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33107

Welcome to JavaRanch!

Note that this thread is 2 years old, so the original poster isn't looking for an answer anymore. For questions about JCreator, note that we have an IDEs forum down below.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

and welcome to the Ranch!
We always appreciate people who take the time to answer questions when they visit
I agree. Here's the link:
subject: ClassNotFoundException Mysql
It's not a secret anymore!