solving paths on the jdbc archive

Michel Maria-Sube <[email protected]> Sun, 19 Apr 2009 02:35:50 -0700 (PDT)
Newsgroups gmane.comp.db.mysql.java
Message-ID <[email protected]>
hello,

I'm working on an application connecting with mysql5, considering that $CLASSPATH is correctly set and piece of code for connection is as follows:

	public void connectDB( String DBname, String user, String passwd ) {
		java.sql.Connection conn = null;
		String	url = null;

		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		}
		catch (ClassNotFoundException cnfe) {
			System.out.println("\nClassNotFoundException occured");
			System.out.println("connection with the DB is not possible");
			cnfe.printStackTrace();
			System.exit(ERROR);
		}
		catch (InstantiationException ie) {
			System.out.println("InstantiationException occured");
			System.out.println("connection with the DB is not possible");
			System.exit(ERROR);
		}
		catch (IllegalAccessException iae) {
			System.out.println("IllegalAccessException occured");
			System.out.println("connection with the DB is not possible");
			System.exit(ERROR);
		}
		try {
			url = new String("jdbc:mysql://localhost/"+DBname+"?user="+user+"&password="+passwd);
.......................

Execution gives following exception:

ClassNotFoundException occured
connection with the DB is not possible
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at MainFrame.connectDB(MainFrame.java:290)
        at MainFrame.createMainScreen(MainFrame.java:260)
        at MainFrame.<init>(MainFrame.java:68)
        at MainFrame.main(MainFrame.java:1049)

This behavior disapears if I update the jar archive for executable with classes content in the jdbc archive but of course I don't want to do that; does anybody could indicate me why java is anable to solve correctly paths in the jdbc archive?

Thank you in advance
Regards
M.

-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/[email protected]