TOMCAT/MYSQL/JSP

From: Kevin Robinson (k.s.robinson_at_btinternet.com)
Date: 12/17/04


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>



Relevant Pages

  • Re: TOMCAT/MYSQL/JSP
    ... > MYSQL using TOMCAT and a jsp. ... > The jdbc driver is in tomcat\common\lib\org.gjt.mm.mysql.Driver. ... > I cannot however get the jsp to access the database. ... > I have a mysql database called bfg and the following jsp: ...
    (comp.lang.java.programmer)
  • Re: Beginner - Netbeans code behind class
    ... >anyone know how I could add a class and use it in my jsp page (similar to ... NetBeans, in particular NetBeans 5.0, can be used ... You may find it easier to learn by using Java Studio Creator to write ... database to MySQL you will have covered most the knowledge you need. ...
    (comp.lang.java.programmer)
  • Java & Intel Xeon Processors
    ... I have a Web site that runs Apache with mysql on Linux. ... take advantage of the multi-threading processor capability? ... Basically the Web site does a lot to read/write to mysql and JSP ...
    (comp.lang.java.programmer)
  • Re: Java Web App Question
    ... JSP are a solid combination. ... struts for MVC. ... sufficient to encapsulate complex code in java classes, ... you can use it directly in your JSP code and with MySQL ...
    (comp.lang.java.programmer)
  • How to connect Jsp with Databases
    ... such as oracle 9i or mysqL which is not install in my PC.They come ... from web hosting company Should i need to install the jdbc driver in ... JSP Beginner ...
    (comp.lang.java)