9 - Sample Code
// The following code can be used as a template. Simply
// substitute the appropriate url, login, and password, and then substitute the
// SQL statement you want to send to the database.
//----------------------------------------------------------------------------
//
// Module: SimpleSelect.java
//
// Description: Test program for ODBC API interface. This java application
// will connect to a JDBC driver, issue a select statement
// and display all result columns and rows
//
// Product: JDBC to ODBC Bridge
//
// Author: Karl Moss
//
// Date: February, 1996
//
// Copyright: 1990-1996 INTERSOLV, Inc.
// This software contains confidential and proprietary
// information of INTERSOLV, Inc.
//----------------------------------------------------------------------------
import java.net.URL;
import java.sql.*;
class SimpleSelect {
public static void main (String args[]) {
String url = "jdbc:odbc:my-dsn";
String query = "SELECT * FROM emp";
try {
// Load the jdbc-odbc bridge driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
DriverManager.setLogStream(System.out);
// Attempt to connect to a driver. Each one
// of the registered drivers will be loaded until
// one is found that can process this URL
Connection con = DriverManager.getConnection (
url, "my-user", "my-passwd");
// If we were unable to connect, an exception
// would have been thrown. So, if we get here,
// we are successfully connected to the URL
// Check for, and display and warnings generated
// by the connect.
checkForWarning (con.getWarnings ());
// Get the DatabaseMetaData object and display
// some information about the connection
DatabaseMetaData dma = con.getMetaData ();
System.out.println("\nConnected to " + dma.getURL());
System.out.println("Driver " +
dma.getDriverName());
System.out.println("Version " +
dma.getDriverVersion());
System.out.println("");
// Create a Statement object so we can submit
// SQL statements to the driver
Statement stm