You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steven Headley <sh...@swbell.net> on 2001/10/22 21:54:08 UTC
newbie question: Setting up MySql JDBC with Tomcat 4.0
Hi all,
I am having problems setting up MySql with Tomcat 4.0 on linux.
Tomcat is working fine. I downloaded and placed mm.mysql-2.0.4-bin.jar
in CATALINA_HOME/lib. I then copied the following jsp from a website:
%@ page import="java.sql.*" %>
<%
String connectionURL =
"jdbc:mysql://localhost/database?user=username;password=****";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM src_cd");
while (rs.next()) {
out.println(rs.getString("SrcCd_Desc")+"");
}
rs.close();
%>
I stopped and restarted tomcat and pointed the browser to the jsp page,
the following is what I got:
I get the following error message:
A Servlet Exception Has Occurred
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occured between lines: 2 and 7 in the jsp file: /test.jsp
Generated servlet error:
/usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002ftest_jsp.java:60:
Class org.apache.jsp.Connection not found.
Connection connection = null;
^
An error occured between lines: 2 and 7 in the jsp file: /test.jsp
Generated servlet error:
/usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002ftest_jsp.java:61:
Class org.apache.jsp.Statement not found.
Statement statement = null;
^
An error occured between lines: 2 and 7 in the jsp file: /test.jsp
Generated servlet error:
/usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002ftest_jsp.java:62:
Class org.apache.jsp.ResultSet not found.
ResultSet rs = null;
^
An error occured between lines: 9 and 21 in the jsp file: /test.jsp
Generated servlet error:
/usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002ftest_jsp.java:71:
Undefined variable or class name: DriverManager
connection = DriverManager.getConnection(connectionURL,
"", "");
^
An error occured between lines: 9 and 21 in the jsp file: /test.jsp
Generated servlet error:
/usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002ftest_jsp.java:80:
Variable rs may not have been initialized.
rs.close();
^
5 errors
could someone please tell me what I did wrong?
Thanks in advance.
Steven H.
Re: newbie question: Setting up MySql JDBC with Tomcat 4.0
Posted by David Smith <dn...@cornell.edu>.
I have a near identical setup with MySQL, TC 4.0.1, Mandrake Linux 8. There
are a couple of things here.
-- the JDBC driver as downloaded is not the jar to be put in Tomcat. It's
actually a zip file with the real .JAR plus source plus docs. Unzip it and
use the jar mm.mysql-2.0.4.jar.
-- the docs for the mysql JDBC driver specs an amperstand character (instead
of semi-colon) between the username and password if you encode them in the
URI. I didn't do that. Instead, I dropped the username and password from
the URI and placed them in where you have ""s in the call to getConnection
example: ... = DriverManager.getConnection( connectionURL, "user", "pass" ) ;
-- last thing I see is that MySQL seems to like a semi-colon at the end of
all SQL statements.
Hope this help you out.
--David Smith
On Monday 22 October 2001 03:54 pm, you wrote:
> Hi all,
> I am having problems setting up MySql with Tomcat 4.0 on linux.
> Tomcat is working fine. I downloaded and placed mm.mysql-2.0.4-bin.jar
> in CATALINA_HOME/lib. I then copied the following jsp from a website:
>
> %@ page import="java.sql.*" %>
> <%
> String connectionURL =
> "jdbc:mysql://localhost/database?user=username;password=****";
> Connection connection = null;
> Statement statement = null;
> ResultSet rs = null;
> %>
>
> <%
> Class.forName("org.gjt.mm.mysql.Driver").newInstance();
> connection = DriverManager.getConnection(connectionURL, "", "");
> statement = connection.createStatement();
> rs = statement.executeQuery("SELECT * FROM src_cd");
>
> while (rs.next()) {
> out.println(rs.getString("SrcCd_Desc")+"");
> }
>
>
> rs.close();
> %>
>
> I stopped and restarted tomcat and pointed the browser to the jsp page,
> the following is what I got:
>
> I get the following error message:
>
> A Servlet Exception Has Occurred
>
> org.apache.jasper.JasperException: Unable to compile class for JSP
>
> An error occured between lines: 2 and 7 in the jsp file: /test.jsp
>
> Generated servlet error:
> /usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002f
>test_jsp.java:60: Class org.apache.jsp.Connection not found.
> Connection connection = null;
> ^
>
>
> An error occured between lines: 2 and 7 in the jsp file: /test.jsp
>
> Generated servlet error:
> /usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002f
>test_jsp.java:61: Class org.apache.jsp.Statement not found.
> Statement statement = null;
> ^
>
>
> An error occured between lines: 2 and 7 in the jsp file: /test.jsp
>
> Generated servlet error:
> /usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002f
>test_jsp.java:62: Class org.apache.jsp.ResultSet not found.
> ResultSet rs = null;
> ^
>
>
> An error occured between lines: 9 and 21 in the jsp file: /test.jsp
>
> Generated servlet error:
> /usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002f
>test_jsp.java:71: Undefined variable or class name: DriverManager
> connection = DriverManager.getConnection(connectionURL,
> "", "");
> ^
>
>
> An error occured between lines: 9 and 21 in the jsp file: /test.jsp
>
> Generated servlet error:
> /usr/local/jakarta/jakarta-tomcat-4.0-b7/work/localhost/struts-logon/_0002f
>test_jsp.java:80: Variable rs may not have been initialized.
> rs.close();
> ^
> 5 errors
>
> could someone please tell me what I did wrong?
>
>
> Thanks in advance.
>
> Steven H.