Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP and MySQL on TomCat

Status
Not open for further replies.

gneti

Programmer
Feb 22, 2003
2
US
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 &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE> Employees List </TITLE>
</HEAD>
<@ page import=&quot;java.sql.*&quot; %>
<BODY>

<TABLE border=1 width=75%>
<TR><TH>Last Name</TH><TH>First Name</TH></TR>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try
{
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;).newInstance();
conn = DriverManager.getConnection(&quot;jdbc:mysql://localhost/cartapp&quot;);
st = conn.createStatement();
rs = st.executeQuery(&quot;select * from employees&quot;);
while(rs.next()){

%>
<TR><TD> <%= rs.getString(&quot;lname_txt&quot;) %> </TD>
<TD><%= rs.getString(&quot;fname_txt&quot;) %> </TR>
<%
}
%>
</TABLE>
<%
}catch(Exception ex) {
ex.printStackTrace();
%>
</TABLE>
Ooops, Something bad happened:
<%
}finally{
if(rs != null) rs.close();
if(st != null) st.close();
if(conn != null) conn.close();
}

%>

</BODY>
</HTML>


I have included the Context Path information in the 'server.xml' file.

<Context path=&quot;/JSPTestSamples&quot; docBase=&quot;E:\JSPTestSamples&quot; debug=&quot;1&quot;
reloadable=&quot;true&quot; crossContext=&quot;true&quot;/>

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;
^

I AM UNABLE to RESOLVE....


Can any OF YOU tell me what's wrong??
 
hi use this
import java.sql.*;
import java.util.*;

public class conn
{
ResultSet rs;
Statement st;
Connection con;
public conn()
{
try
{
Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);
con=DriverManager.getConnection(&quot;jdbc:mysql://localhost/fire&quot;,&quot;&quot;,&quot;&quot;);



st=con.createStatement();
}catch(Exception se){System.err.println(se.getMessage());}
}

}

anruag_shr@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top