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.Clas sNotFoundExcept ion: 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(J DBC_DRIVER);
connection = DriverManager.g etConnection(DA TABASE_URL);
//if connected to database, output String
if (!connection.is Closed())
System.out.prin tln("CONNECTED TO THE DATABASE");
}
catch ( SQLException e ) //exception in SQL query
{
e.printStackTra ce();
} // end catch
catch ( ClassNotFoundEx ception e ) //exception in Class connection
{
e.printStackTra ce();
} // end catch
/*catch ( InstantiationEx ception e ) //exception in Class connection
{
e.printStackTra ce();
} // end catch
catch ( IllegalAccessEx ception e ) //exception in Class connection
{
e.printStackTra ce();
} // end catch*/
}
...
Any ideas?
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.Clas sNotFoundExcept ion: 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(J DBC_DRIVER);
connection = DriverManager.g etConnection(DA TABASE_URL);
//if connected to database, output String
if (!connection.is Closed())
System.out.prin tln("CONNECTED TO THE DATABASE");
}
catch ( SQLException e ) //exception in SQL query
{
e.printStackTra ce();
} // end catch
catch ( ClassNotFoundEx ception e ) //exception in Class connection
{
e.printStackTra ce();
} // end catch
/*catch ( InstantiationEx ception e ) //exception in Class connection
{
e.printStackTra ce();
} // end catch
catch ( IllegalAccessEx ception e ) //exception in Class connection
{
e.printStackTra ce();
} // end catch*/
}
...
Any ideas?
Comment