connection to mysql using jsp
Posted by: junia phiong
Date: November 27, 2005 05:27AM

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....

Options: ReplyQuote


Subject
Written By
Posted
connection to mysql using jsp
November 27, 2005 05:27AM
September 24, 2006 10:26AM
December 27, 2007 11:53PM
December 31, 2007 09:54PM
February 19, 2006 11:57PM
b g
June 09, 2009 04:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.