Help JSP connecting to Access

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    Help JSP connecting to Access

    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\jsp tests\". 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.j sp
    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_0 1
    PATH %SYSTEMROOT%\SY STEM32;%SYSTEMR OOT%;%SYSTEMROO T%\SYSTEM32\W
    BEM;C:\DMI\WIN3 2\BIN;C:\Docume nts and
    Settings\ahlcu\ jswdp-1_0\bin;C:\j2sd k1.4.1_01\bin

    Here's the code:

    <%@ page import="java.sq l.*" %>
    <%@ page import="java.io .*" %>
    <%@ page import="java.ut il.*" %>
    <%@ page import="java.te xt.*" %>

    <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.J dbcOdbcDriver") .newInstance();

    //Get the connection getConnection(" access driver", "userID",
    "password")
    con = DriverManager.g etConnection("j dbc:odbc:Access Paul","myUserID ","myPassword") ;

    stmt = con.createState ment();

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

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

    <%= result %> </br>

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

    </body>
    </html>
  • Wendy S

    #2
    Re: Help JSP connecting to Access

    "Paul" <pcma10019@yaho o.com> wrote:[color=blue]
    > I'm trying to connect to an Access database using tomcat.[/color]

    Answered in comp.lang.java. programmer

    --
    Wendy


    Comment

    Working...