MySQL Forums
Forum List  »  Newbie

mysql driver loading trouble
Posted by: adam l
Date: May 29, 2005 11:23AM

my teamates and i for a class project cannot solve this one. we are attempting to open a connection to campus mysql server. our problem is we get an exception durring the call to:

Class.forName("com.mysql.jdbc.Driver").newInstance();

i've condensed the problem into a small test program which has the same error. here is the program (i'm sorry about the lack of indentation, i tried replacing the tabs with spaces and it didn't work):

------------------------------------------------------------------------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;

public class DatabaseController
{
public static void main(String[] args)
{
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception e) {System.out.println("main error: " + e.getMessage());}
DatabaseController database = new DatabaseController();
database.DatabaseController();
}

public Connection conn;
public void DatabaseController()
{
try
{
String userName = "<REMOVED>";
String password = "<REMOVED>";
String url = "jdbc:mysql://mysql.cs.orst.edu:3306:cs362";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Error in databaseController: " + e.getMessage ());
e.printStackTrace();
}
finally
{
if (conn != null)
try {conn.close();} catch (Exception e) {System.out.println("close error");}
}
}
}
------------------------------------------------------------------------------

and here is the exception and stacktrade:

main error: com.mysql.jdbc.Driver (THROWN IN MAIN)
Error in databaseController: com.mysql.jdbc.Driver (THROWN IN DATABASECONTROLLER)
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.<init>(Throwable.java:87)
at java.lang.Exception.<init>(Exception.java:35)
at java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:62)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(Compiled Code)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:290)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:117)
at DatabaseController.DatabaseController(DatabaseController.java:26)
at DatabaseController.main(DatabaseController.java:15)

all help appreciated.

Options: ReplyQuote


Subject
Written By
Posted
mysql driver loading trouble
May 29, 2005 11:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.