From - Sat Jun 14 21:41:59 1997
Path: world1.bellatlantic.net!out2.nntp.cais.net!in1.nntp.cais.net!azure.xara.net!xara.net!peernews.ftech.net!telehouse1.frontier-networks.co.uk!peernews.paralex.co.uk!paralex!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.internetmci.com!news.ns.net!innercite.com!not-for-mail
From: "Richard A. Porter" <richardp@examen.com>
Newsgroups: comp.lang.java.databases
Subject: Re: Demo available for ODBC ?
Date: Tue, 03 Jun 1997 13:58:06 -0700
Organization: Examen
Lines: 96
Message-ID: <3394855E.1BD45FC2@examen.com>
References: <3392A451.41C6@perrin.demon.co.uk> <3392EEEE.6EE4@trifox.com>
NNTP-Posting-Host: 158.222.64.141
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.0b5 [en] (WinNT; I)
X-Priority: 3 (Normal)

Bob Eisner wrote:
> 
> Peter Lord wrote:
> >
> > Please excuse my ignorance with Java, but I am currently looking
> > around to see what is the best method to write intranet front-ends
> > to our various corporate databases.
> >
> > We mainly use Oracle (on UNIX) and Access (on NT).
> >
> > I need to have nice pretty forms on the intranet, where simple selects,
> > inserts and updates to the databases can be done.  At the moment, I
> > only have intranet front-ends for the Oracle databases but this is
> > quite crude (rsh / sqlplus type cgi scripts).
> >
> > Looking around the market, learning Java and using JDBC/ODBC would
> > be a pretty good option.  I would then be able to enhance my intranet
> > applications to read/write data to both Oracle and Access database.
> >
> > However, I've been looking around to see how JDBC/ODBC works ... and
> > it does seem very confusing.
> >
> > Does anyone know if there is a minimal Java demo program which attaches
> > to an Access database running on NT and does something simple like
> > a select.... This would help me to evaluate whether Java is the right
> > tool to use or not.
> >
> > Many thanks,
> >
> > Peter Lord
> 

[snip]

Here's a quickie I put together for you.

import java.sql.*;
import java.net.URL;

/*****************************************************************
  This is a simple demo of the jdbc-odbc bridge.
  To use without changing the code, be sure to have a data source
  named database1 set up in ODBC. I set this up with Access.
  RAP
                          6/3/97 1:40PM
*****************************************************************/
public class Demo
{

  public static void main(String[] args)
  {
    Connection con;
    Statement stmt;
    ResultSet rs;
    ResultSetMetaData rsmd;
    int colCount;
    String url = "jdbc:odbc:database1";

    try
    {
// this is the class file that will handle the connection
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      con = DriverManager.getConnection(url, "", "");

      stmt = con.createStatement();

// this result set will contain the data, and will be able to report
// on its meta data (see below)
      rs = stmt.executeQuery("select * from emp");

// meta data contains information about the intent of the table
      rsmd = rs.getMetaData();

      colCount = rsmd.getColumnCount();

      while ( rs.next() )
// watch out, ResultSets use a 1-based index
        for ( int i = 1; i <= colCount; i++ )
// this assumes that all your columns are strings!!!
          System.out.println(rs.getString(i));
      rs.close();
      con.close();

    }
    catch( Exception e )
    {
      e.printStackTrace();
    }

  } // finish main
} // finish class Demo


Richard A. Porter
Examen
