TOMCAT/MYSQL/JSP
From: Kevin Robinson (k.s.robinson_at_btinternet.com)
Date: 12/17/04
- Next message: codemaster: "getting mysql-data with jconnector"
- Previous message: Chris Hatton: "Re: Help for a newbee please!"
- Next in thread: Luke Webber: "Re: TOMCAT/MYSQL/JSP"
- Reply: Luke Webber: "Re: TOMCAT/MYSQL/JSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 17 Dec 2004 11:44:48 +0000 (UTC)
Can anyone please advise me about a problem I have trying to connect to
MYSQL using TOMCAT and a jsp.
I have tomcat 4.1.24 , mysql 4.1.7 and the jdbc driver 2.0.14.
The jdbc driver is in tomcat\common\lib\org.gjt.mm.mysql.Driver.
The classpath includes c:\tomcat\common\lib.
I cannot however get the jsp to access the database.
I tried a userid and a password in the jsp but it still didn't work
Can anyone tell me what is wrong???
I have a mysql database called bfg and the following jsp:
<HTML>
<HEAD><TITLE>Employee List</TITLE></HEAD>
<BODY>
<%@ 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;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bfg");
st = conn.createStatement();
rs = st.executeQuery("select * from employees");
while(rs.next()) {
%>
<TR><TD><%= rs.getString("lname_txt") %></TD>
<TD><%= rs.getString("fname_txt") %></TD></TR>
<%
}
%>
</TABLE>
<%
} catch (java.sql.SQLException 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>
- Next message: codemaster: "getting mysql-data with jconnector"
- Previous message: Chris Hatton: "Re: Help for a newbee please!"
- Next in thread: Luke Webber: "Re: TOMCAT/MYSQL/JSP"
- Reply: Luke Webber: "Re: TOMCAT/MYSQL/JSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|