Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 6th, 2003, 09:52 PM
Authorized User
Join Date: Jul 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem: JSP connecting to MS Access


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
    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.*" %>


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

//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);


<%= result %> </br>

}catch (Exception e) {


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.

Old August 7th, 2003, 01:54 AM
Authorized User
Join Date: Jul 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yuji_chen

Make sure ur code have run into the while loop, else it is correctly display in the browser coz ur result is inside the loop....

Old August 8th, 2003, 04:40 PM
Authorized User
Join Date: Aug 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

Nothing obvious to me (but it's late). I'd stick a number of debug messages in the code (out.println and/or <%= %>) to see what's happening and what values the various objects have.

 - Peter

Old August 12th, 2003, 12:07 PM
Authorized User
Join Date: Jul 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

I got this one to work. I modified the part where the result set gets played....

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access connecting to Oracle Problem Corey Oracle 2 March 21st, 2007 02:52 AM
MS Access - Connecting to dartcoach VB.NET 2002/2003 Basics 2 February 27th, 2007 12:05 PM
Connecting MS Access using Struts roopesh_dubey Struts 0 February 18th, 2007 02:43 AM
connecting PHP to MS Access pb7 Beginning PHP 5 September 24th, 2004 05:04 PM
connecting PHP to an MS Access database pb7 PHP Databases 1 September 18th, 2003 04:28 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.