LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-17-2006, 02:43 AM   #1
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Rep: Reputation: 30
Configuring JSP and MySQL


Hi,
It is my first day working with JSP so I am not quite familiar with it. I am going to deploy a small database program using JSP on tomcat. I have downloaded MySQL Connector/J and extracted it on my hard disk and then copied the jar file to following directory like this:

Code:
cp softs/mysql-connector-java-5.0.4/mysql-connector-java-5.0.4-bin.jar /usr/local/tomcat/webapps/ROOT/WEB-INF/lib/
I have a database called employee and a table inside it called employees in /var/lib/mysql/ directory
Here is my JSP file:

Code:
<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/employee?user=root;password=esteghlal");
	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>
Ooops, something bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</BODY>
</HTML>
But at the end I am not able to see the list.

I would be glad if someone helps me.

Thanks
 
Old 12-17-2006, 02:46 AM   #2
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
Sorry for wasting your time. I figured out where the problem is.
I should use & instead of ; in the following line:
conn = DriverManager.getConnection("jdbc:mysql://localhost/employee?user=root&password=esteghlal");
 
  


Reply

Tags
jsp, mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP and MySQL - unable to load JDBC driver jun_tuko Programming 2 09-05-2006 11:02 AM
connectivity of jsp file with mysql in fedora core 4 anshu.rahul Fedora 0 05-03-2006 07:37 AM
Need basic code to connect to MySQL using JSP / JAVA jun_tuko Programming 4 01-16-2006 03:15 AM
[ JSP/JAVA ] MySQL connection fails White R4bbit Programming 4 04-27-2005 08:31 AM
an error occur when jsp connect to mysql? shitian8848 Programming 2 06-04-2004 02:08 PM


All times are GMT -5. The time now is 05:28 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration