Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with Tomcat 6.0 / connector/j / jdk1.6 /JDBC

843859Sep 5 2007 — edited Nov 20 2014
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2007
Added on Sep 5 2007
11 comments
89 views