473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 3810
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.