File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes problem with JSP, mySQL on TomCat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "problem with JSP, mySQL on TomCat" Watch "problem with JSP, mySQL on TomCat" New topic

problem with JSP, mySQL on TomCat

Gayathri Neti

Joined: Mar 08, 2002
Posts: 25
Hi All,
I am new to this. I am trying to write a simple application in JSP to access MySQL on TomCat4.1.18.
I have downloaded the MySQL JDBC Driver from
I have copied the mm.mysql-2.0.14-bin.jar into 'lib' directory under my TomCat Default installation directory (E:/jakarta-tomcat-4.1.18/server/lib).
I have written this JSP :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE> Employees List </TITLE>
<@ page import="java.sql.*" %>
<TABLE border=1 width=75%>
<TR><TH>Last Name</TH><TH>First Name</TH></TR>
Connection conn = null;
Statement st = null;
ResultSet rs = null;
conn = DriverManager.getConnection("jdbc:mysql://localhost/cartapp");
st = conn.createStatement();
rs = st.executeQuery("select * from employees");
<TR><TD> <%= rs.getString("lname_txt") %> </TD>
<TD><%= rs.getString("fname_txt") %> </TR>
}catch(Exception ex) {
Ooops, Something bad happened:
if(rs != null) rs.close();
if(st != null) st.close();
if(conn != null) conn.close();

I have included the Context Path information in the 'server.xml' file.
<Context path="/JSPTestSamples" docBase="E:\JSPTestSamples" debug="1"
reloadable="true" crossContext="true"/>
When I execute in the browser, I get
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 10 in the jsp file: /employees_list.jsp
Generated servlet error:
[javac] Compiling 1 source file
E:\jakarta-tomcat-4.1.18\work\Standalone\localhost\JSPTestSamples\ cannot resolve symbol
symbol : class Connection
location: class org.apache.jsp.employees_list_jsp
Connection conn = null;

Can any OF YOU tell me what's wrong??
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I think the problem is that, there is conflict of which Connection object you want the compiler to use. Either the java.sql.Connection object or the one provided by the third party driver You must keep in mind that alot of these third party drivers have there own implementations of the java.sql package. Also
whenever possible try following the coding recommendation of explicitly declaring all non-implicit objects in your import statements.
Dean Reedy
Ranch Hand

Joined: Sep 10, 2001
Posts: 89
You might try this:

It is just a little different. You will need to replace variables: host,db,user,pass in the conn string. Hope this helps.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I think Dean's example will work also.
But after taking a second look at your code Gayathri. It appears that your page declaration is incorrect. You have:

Which should be:
Your missing a
, which is probably why your are not correctly importing the java.sql package, which means it doesn't know what Connection object you are taking about. But I am surprised the compiler did not pick it up sooner.
Give it try.
I agree. Here's the link:
subject: problem with JSP, mySQL on TomCat
It's not a secret anymore!