aspose file tools*
The moose likes JDBC 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
Bookmark "ClassNotFoundException Mysql" Watch "ClassNotFoundException Mysql" New topic
Author

ClassNotFoundException Mysql

Vince Black
Greenhorn

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.net.URLClassLoader.findClass(URLClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:516)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:142)
at Database.main(Database.java:12)
My Code is :
import java.sql.*;
import java.io.*;
import java.util.Properties;
public class Database
{
public static void main( String args[] )
{
try
{
// Register MySQL driver
Class.forName("com.mysql.jdbc.Driver").newInstance();

// Open a properties file where connection info is stored
FileInputStream infile = new FileInputStream( "db.properties" );
Properties props = new Properties();
props.load(infile);
// 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
System.out.println("ID\tName");
System.out.println("--\t----");
while (rs.next())
{
System.out.println(rs.getString("id")+"\t"+rs.getString("name"));
}
// Close everyting
rs.close();
stat.close();
conn.close();
}
catch (Exception ex)
{
System.out.println( "An exception has been intercepted" );
ex.printStackTrace();
}
}
}
i dont know the Problem i am a Newbie
thx
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

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
Greenhorn

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
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

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
CLASSPATH=\path\to\mysql-connector-java-[version]-bin.jar;%CLASSPATH%
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�
Greenhorn

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
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Tomi,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

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: http://aspose.com/file-tools
 
subject: ClassNotFoundException Mysql