JDBC/ODBC Bridge Sample

This sample is located in \Samples\Jdbc.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

This sample, SimpleSelect.java, demonstrates how to use the Microsoft JDBC/ODBC bridge. The relevant classes are part of the com.ms.jdbc.odbc package. If you have been using the classes provided by the older package com.ms.sql.CDriver, change the package name in the source to com.ms.jdbc.odbc.JdbcOdbcDriver.

To use this sample, the following must be installed:

Using the Sample

To compile the sample

  1. Use the ODBC driver manager to define a valid ODBC data source. Follow the instructions in the ODBC help file.

  2. Change the following lines in SimpleSelect.java:
    String url = "JDBC:ODBC:<my_dsn>;";

    Change <my_dsn> to the name of the data source.

    String query = "SELECT * FROM <authors>";

    Change <authors> to the name of an existing table.

    Connection con = DriverManager.getConnection (url, <"my_user">, <"my_passwd">);

    Change <"my_user"> and <"my_passwd"> to the appropriate user name and password.

  3. Use Nmake.exe to compile the makefile in the \Samples\Jdbc directory.

Example

If you have Microsoft® Access installed and want to use the Northwind sample database, do the following:

  1. Create an ODBC data source and type Northwind for the data source name.

  2. Modify SimpleSelect.java as follows:
    String url = "JDBC:ODBC:Northwind;"; // for SimpleSelect.java
    String query = "SELECT * FROM Customers";
    Connection con = DriverManager.getConnection (url, "", "");
    
  3. Run nmake to compile makefile in \Samples\Jdbc. The makefile runs jvc to compile SimpleSelect.java.

To run the sample

Use the following command to run SimpleSelect:

jview SimpleSelect

Key Project Files

SimpleSelect.java

This file contains the main application code for accessing the ODBC data store.

Technologies Demonstrated

JDBC

© 1999 Microsoft Corporation. All rights reserved. Terms of use.