• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

problem with JSP, mySQL on TomCat

Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 www.sourceforge.net/projects/mmmysql/.
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\employees_list_jsp.java:57: 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??
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 org.gjt.mm.mysql.Connection. 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.
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!