472,794 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

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

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
3 3769
shegoj
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
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
ajos
283 100+
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

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

Similar topics

2
by: bouchia.nazha | last post by:
Hello I have encountered a problem using tomcat, linux and ssl. My problem seem to be a JVM memory deallocation problem on Linux. This is my configuration: OS: Redhat7.2 Tomcat: 4.0 Jdk:...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
1
by: ab | last post by:
hi all, we've installed MySQL on a Windows XP machine, but cannot connect to it using JSP/Servlet. An error message comes up saying: java.sql.SQLException: General error, message from server:...
2
by: Marc Stiegele | last post by:
Hello, I have a problem with the IBM DB2 UDB XML Extender. I`m working on a iSeries 400 server (AS/400, V5R1) with a integrated DB2 (my client is NT 4.0 Service Pack 1 with JDK1.1.8). I want to...
10
by: sssk28 | last post by:
i have installed fedora core 6 and i am getting following error: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this...
0
by: hexborg | last post by:
I'm Trying to connect a JSP tomcat-based application to Oracle using OracleConnectionPoolDataSource and related classes. I have used javax.sql.DataSource an it did work fine. I have made changes...
5
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql server with java application but when i try to compile,the compilation is successful and during execution i get the following message, ...
1
by: sethupnr | last post by:
when i'm using a simple JSP-mysql code it shows some HTTP status 500 error.But simple JSP program without databse is running , Please help how to solve this problem. I'm new to JSP. my...
6
by: shivapadma | last post by:
i want to access mysql database server from jsp program for this i downloaded mysql-connector-java-3.1.14.zip mysql-connector-java-3.1.14 folder contains mysql-connector-java-3.1.14-bin.jar...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.