Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cannot connect to mysql database via connector/j

843859Nov 21 2006 — edited Feb 19 2007
Hi guys,

one question that really seems to be very stupied, but I cannot get to work the following program:
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.naming.*;
import javax.sql.*;


public class SQLClass{
	public static void main(String[] args){
		try{
			Class.forName("com.mysql.jdbc.Driver");
		}
		catch(ClassNotFoundException e){
			System.err.println("no driver class found!");
			e.printStackTrace();
			return;
			}
		Connection con = null;
	    try{
	    	con = DriverManager.getConnection("jdbc:mysql://localhost/MY_DB_NAME", "DB_USER_NAME", "DB_USER_PW");
	    }
	    catch(SQLException e){
	    	e.printStackTrace();
	    	return;
	    }
	    finally{
	    	if ( con != null )
	        try{ 
	        	con.close();
	        } 
	      	catch(SQLException e){ 
	      		e.printStackTrace(); 
	      	}
	    }
	  }
	}
the following components are installed in the listed locations:
xampp for windows 1.5.4a (inkl. MySQL 5.0.24a) at T:\Programme\xampp
connector/J (mysql-connector-java-3.1.7-bin.jar) at C:\
the above program at C:\
command line> echo %CLASSPATH% 
yields C:\mysql-connector-java-3.1.7-bin.jar, so the jar file is set in the CLASSPATH correctly
The MySQL is stared up (recognized by "netstat" as well as phpMyAdmin) and its the Database' name as well as the user rights are set appropriate.
command line (at C:\)>javac SQLClass.java
yields nothing (in other words class file becomes build correctly)
then
command line (at C:\)>java -cp . SQLClass
yields
no driver class found!
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at SQLHandling.main(SQLHandling.java:11)

can someone explaine me why???

I really got absolutely no clue, even the dependences of the used connector/j and the used mysql version holds...

thanks for your help

hth

Tom

PS: using java 1.4.2_13-b06 (but this shouldn't matter)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2007
Added on Nov 21 2006
8 comments
345 views