K
Kevin Robinson
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>
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>