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 called "lib" & "classes".
I then open I.E. and type the url
http://localhost:8080/jsptests/AccessConnect.jsp
All I'm getting on the browser is the message, "You are connected!". The result of my query is not being displayed. I tried using both the codes: out.println(result); and <%= result %> </br> to no avail.
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%\SY STEM32\W BEM;
C:\DMI\WIN32\BIN;C:\Documents and Settings\ahlcu\jswdp-1_0\bin;C:\j2sdk1.4.1_01\bin
<%@ 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").newI nstance();
//Get the connection getConnection("access driver", "userID", "password")
con = DriverManager.getConnection("jdbc:odbc:myDB","myID ","myPass");
out.println("You are connected!");
stmt = con.createStatement();
//sql statements: create, update, query
rs = stmt.executeQuery(queryString);
while (rs.next()) {
String result = rs.getString(1);
out.println(result);
%>
<%= result %> </br>
<%
}
rs.close();
}catch (Exception e) {
System.out.println(e);
}
%>
</body>
</html>
Am I coding the part where I'm trying to display the resultset correctly? Can someone tell me what I'm doing wrong. I would really appreciate it.