By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,467 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,467 IT Pros & Developers. It's quick & easy.

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

P: 2
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?
Sep 5 '07 #1
Share this Question
Share on Google+
3 Replies


P: 1
Hi,

Drop the connector .jar in your $JAVA_HOME/jre/lib/ext directory, then retry your code. If the code works , then the problem has to do with setting your class path, else it could be that you are using bad/wrong .jar.

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?
Sep 5 '07 #2

P: 2
It is already there. Perhaps it is a problem with the classpath then. What should it be set to? I set it to the directory that the connector .jar file is in (along with the servlet -api and jsp-api .jar files)
Sep 6 '07 #3

100+
P: 283
It is already there. Perhaps it is a problem with the classpath then. What should it be set to? I set it to the directory that the connector .jar file is in (along with the servlet -api and jsp-api .jar files)
hi, this is how i set it in the environment variables(ClassPath)-
;C:\Program Files\mysql-connector-java-5.1.2-beta\mysql-connector-java-5.1.2-beta-bin.jar....beginning with a semicolon(;)
Sep 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.