Hello,
I'm trying to write a jsp page that calls a java class, which accesses a MYSQL database, and for some reason i get "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" while trying to establish the connection. I tried putting the connector .jar in the WEB-INF\lib, I tried setting the classpath variable to the connector's location, and nothing seems to fix it. Am I using the wrong class for the driver, or is it something else.
Here is the connection code:
import java.sql.*;
import java.util.*;
import javax.swing.*;
import com.sun.rowset.JdbcRowSetImpl;
public class DatabaseApp
{
static Connection connection;
static Statement statement;
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/mydatabase?user=blah&password=blahblah";
public DatabaseApp()
{
connection = null;
statement = null;
//connect to the database
try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL);
//if connected to database, output String
if (!connection.isClosed())
System.out.println("CONNECTED TO THE DATABASE");
}
catch ( SQLException e ) //exception in SQL query
{
e.printStackTrace();
} // end catch
catch ( ClassNotFoundException e ) //exception in Class connection
{
e.printStackTrace();
} // end catch
/*catch ( InstantiationException e ) //exception in Class connection
{
e.printStackTrace();
} // end catch
catch ( IllegalAccessException e ) //exception in Class connection
{
e.printStackTrace();
} // end catch*/
}
...
Any ideas?