/*
 * [ConnectJDBCODBCBridge.java]
 *
 * Summary: Demonstrate the how to connect to a Microsoft Access via JDBC and the ODBC bridge.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2007-09-22
 */
package com.mindprod.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static java.lang.System.*;

/**
 * Demonstrate the how to connect to a Microsoft Access via JDBC and the ODBC bridge.
 * <p/>
 * better performance with a direct JDBC bridge. see http://developers.sun.com/product/jdbc/drivers
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2007-09-22
 * @since 2007-09-22
 */
@SuppressWarnings( { "WeakerAccess", "UnusedDeclaration" } )
public class ConnectJDBCODBCBridge
    {
    /**
     * which database
     */
    private static final String DATABASENAME = "SQUIRRELS";

    /**
     * class name of the JDBC driver
     */
    private static final String DRIVERCLASSNAME = "sun.jdbc.odbc.JdbcOdbcDriver";

    /**
     * access PASSWORD
     */
    private static final String PASSWORD = "sesame";

    /**
     * login name of user
     */
    private static final String USERNAME = "charlie";

    /**
     * The connection.  Handle to the database
     */
    private static Connection conn;

    /**
     * connect to the database
     *
     * @return Connection to the database
     * @throws java.sql.SQLException
     */
    private static Connection connect() throws SQLException
        {
        try
            {
            Class.forName( DRIVERCLASSNAME );
            }
        catch ( Exception e )
            {
            err.println( "can't load ODBC bridge JDBC driver: "
                         + e.getMessage() );
            }
        return DriverManager.getConnection( "jdbc:odbc:" + ":" + DATABASENAME,
                USERNAME,
                PASSWORD );
        }

    /**
     * initialise the database
     *
     * @param args not used
     *
     * @throws java.sql.SQLException
     */
    public static void main( String[] args ) throws SQLException
        {
        conn = connect();
        // ...
        conn.close();
        }
    }