Original Post
Hi, I have the following code wich works fine for connecting to my sql database.
import java.sql.*;
import javax.swing.*;
import java.util.*;
public class MySqlConnector
{
public MySqlConnector(String user,String password, ArrayList theTeams)
{
try
{
String url="jdbc:mysql://localhost/tournament?" +
"user=usr101&password=pass";
String driver="org.gjt.mm.mysql.Driver";
// Produces the driver needed for a JDBC connection
try
{
Class.forName(driver);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,
"Couldn't find driver: " + e.getMessage());
}
// Attempts to make connection with driver
Connection con = DriverManager.getConnection(url);
// Checks the user name and password
String query ="SELECT * FROM users WHERE username = '" + user +
"' AND password = '" + password + "' AND admin = '1';";
Statement stmt = con.createStatement();
ResultSet RS = stmt.executeQuery(query);
if(RS.next()) // User ID and password are valid
{
// System started
IDGen iDG = new IDGen();
int tournamentID = iDG.generateID(con);
Tournament tourny = new Tournament(theTeams, con, tournamentID);
}
else
{
// Connections and statements terminated
stmt.close();
con.close();
// Show access denied dialog.
JOptionPane.showMessageDialog(null,"Invalid userID/password");
// Restart login process.
Login loginScreen = new Login(theTeams);
}
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
}
}
}
However when I package my classes up in a jar file the connection no longer works and I get this error... Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver Any ideas why this might be happening ? Do I need to add something similar to the getClass().getResource() code for getting resources, if so where do I use it ? Thanks for any ideas... Chris