connection to mysql using jsp
Hi,
Hope any one can help me or teach me how to call mysql in jsp file....
I am new doing my final year project and I am new in mysql and JSP. I try out the example from mysql and JSP webapplication sam publisher book. I already create a table in mysql and I want to connect to run it in the tomcat server but its prompt out error
I think is my problem is in the mmmysql driver connection I already install but I don't know whats the problem it have this error:
"An error occurred at line: 9 in the jsp file: /employee_list.jsp
Generated servlet error:
The method forname(String) is undefined for the type Class
"
This is mysql database table I save in the bin directory of mysql folder that I just installed.
----------------------------------------------------------------
drop table IF EXIST employees;
create table employees(
lname_txt CHAR(50),
fname_txt CHAR(50),
employee_num INTEGER PRIMARY KEY,
address1_txt CHAR(120),
address2_txt CHAR(120),
city CHAR(50),
state CHAR(2),
zip CHAR(10),
phone CHAR(14));
insert into employees values
('Junia', 'Phiong', 1, 'Trust HAll', NULL, 'Springfield', 'MA' '79111', '1111111');
insert into employees values
('June', 'Bong', 2, 'JAmes watson', NULL, 'Park Road', 'ST' '93000', '2222222');
----------------------------------------------------------------
and here is the jsp file that I saw in the book
<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");
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 (Exception ex) {
ex.printStackTrace();
%>
</TABLE>
Oooops, Something bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</BODY>
</HTML>
----------------------------------------------------------------
NB: mysql file: mysql-bin-employees.sql
tomcat-webapp-root-employee_list.jsp
and I just run it in tomcat straigh away run it in tomcat server and it have error actually I think I do the wrong step I not sure how to run please anyone can help me to solve my problem thank you....
Subject
Written By
Posted
November 15, 2006 04:20AM
November 15, 2006 10:57AM
connection to mysql using jsp
November 27, 2005 05:27AM
September 24, 2006 09:39AM
September 24, 2006 10:26AM
December 27, 2007 11:53PM
December 31, 2007 09:54PM
February 15, 2006 12:12AM
February 19, 2006 11:57PM
February 20, 2006 01:46AM
December 14, 2007 01:11AM
February 20, 2006 12:20AM
November 15, 2006 04:15AM