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"> <HTML> <HEAD> <TITLE> Employees List </TITLE> </HEAD> <@ page import="java.sql.*" %> <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("org.gjt.mm.mysql.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://localhost/cartapp"); st = conn.createStatement(); rs = st.executeQuery("select * from employees"); while(rs.next()){ %> <TR><TD> <%= rs.getString("lname_txt") %> </TD> <TD><%= rs.getString("fname_txt") %> </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="/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; ^ I AM UNABLE to RESOLVE....
Can any OF YOU tell me what's wrong??
Craig Jackson
Ranch Hand
Joined: Mar 19, 2002
Posts: 405
posted
0
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. craig.
Dean Reedy
Ranch Hand
Joined: Sep 10, 2001
Posts: 89
posted
0
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. Dean
Craig Jackson
Ranch Hand
Joined: Mar 19, 2002
Posts: 405
posted
0
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. Craig.