Help JSP connecting to Access

P

Paul

Hi,

I'm trying to connect to an Access database using tomcat. I'm new to
JSP so I'm not sure whether I'm doing the right thing. I'm saving the
code below as "AccessConnect.jsp" under
"jakarta-tomcat-4.0\webapps\jsptests\". Under the folder jsptests is
an empty subfolder called "WEB-INF". Under this folder are two empty
folders calles "lib" & "classes".

I then open I.E. and type the url
ttp://localhost:8080/jsptest/AccessConnect.jsp
I'm getting page not found. Can someone tell me what am I doing wrong.
Am I supposed to compile something or Tomcat is supposed to do that
automatically? Thanks.

I also have the following variables setup on Windows 2000 NT:
CATALINA_HOME c:\jakarta-tomcat-4.0
CLASSPATH c:\jakarta-tomcat-4.0\common\lib\servlet.jar;.
JAVA_HOME c:\j2sdk1.4.1_01
PATH %SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%;%SYSTEMROOT%\SYSTEM32\W
BEM;C:\DMI\WIN32\BIN;C:\Documents and
Settings\ahlcu\jswdp-1_0\bin;C:\j2sdk1.4.1_01\bin

Here's the code:

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>

<html>
<body>
<%

//instantiate variables
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String queryString;
queryString = "select COF_NAME, PRICE from COFFEES";

try
{
//Load the JDBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

//Get the connection getConnection("access driver", "userID",
"password")
con = DriverManager.getConnection("jdbc:eek:dbc:AccessPaul","myUserID","myPassword");

stmt = con.createStatement();

//sql statements: create, update, query
rs = stmt.executeQuery(queryString);

while (rs.next()) {
String result = rs.getString("name");
%>

<%= result %> </br>

<%
}
rs.close();
}catch (Exception e) {
System.out.println(e);
}
%>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top