package org.mbari.seepsearch.db;

import java.sql.*;
import javax.sql.*;		    // extended	JDBC package


/**
 * <p>This class establishes a connection to the VIMS database. It currently
 * uses an ODBC driver but this will be changed to a SQL driver.</p>
 *
 * <p>The Seep Search project is a sub-project of the Continental
 *  Margin Fluids and Gases project (200010). It involves the analysis of
 *  archived ROV data to obtain understanding of seep distritution in Monterey
 *  Bay.</p>
 *
 *  <p>The Purpose of this Java package is to intercompare ROV Navigation files,
 *  VIMS data on seep community observations and the EM-300 bathymetry. We are
 *  looking for locations where the ROV navigation files and the EM-300 data
 *  have similar depths between the 2 data sets, which implies that the ROV is
 *  observing the sea floor.</p><hr><br>
 *
 * <p>MBARI provides this documentation and code &quot;as is&quot;, with no
 * warranty, express or implied, of its quality or consistency. It is provided
 * without support and without obligation on the part of the Monterey Bay
 * Aquarium Research Institute to assist in its use, correction, modification,
 * or enhancement. This information should not be published or distributed to
 * third parties without specific written permission from MBARI.</p><br>
 *
 * Copyright 2002 MBARI.<br>
 * MBARI Proprietary Information. All rights reserved.<br><hr><br>
 *
 * $Log: VimsConnection.java,v $
 * Revision 1.4  2002/04/17 21:48:51  brian
 * Adding Vars Database support. Moving to IRovNavigationIterator as the common interface between disparate datasets
 *
 * Revision 1.3  2002/01/30 00:23:56  brian
 * Added comments to all classes and methods. Tested the accuracy of AsciiRasterGridReader and AsciiRasterGridWriter. Also checked the the GridUtil was populating the spatial grids correctly and accurately. The data files generated matched up perfectly with the orginal text files. Also implemented an RovAltitudeFilter class to encapsulate different filtering methods.
 *<br><hr><br>
 *
 * @author  : $Author: brian $
 * @version : $Revision: 1.4 $
 */
public class VimsConnection {

    public VimsConnection() throws ClassNotFoundException, SQLException,
        IllegalAccessException, InstantiationException {
        this.con = getConnection();
    }

    private Connection getConnection() throws ClassNotFoundException,
     SQLException, IllegalAccessException, InstantiationException {

        String login = "everyone";
        String password = "guest";

        // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");	//ODBC
        Class.forName("com.inet.pool.PoolDriver").newInstance(); //Opta2000
        // create a DataSource
        com.inet.tds.TdsDataSource tds = new com.inet.tds.TdsDataSource();
        tds.setServerName( "godzilla" );
        tds.setDatabaseName( "vims" );
        tds.setUser( login );
        tds.setPassword( password );
        tds.setLoginTimeout( 10 );
        tds.setDescription( "VIMS KnowledgeBase Data Base" );
        DataSource ds = tds;

        //open a connection to the database
        Connection databaseConnection = ds.getConnection(login, password);

        return databaseConnection;
    }

    public ResultSet executeQuery(String query) throws SQLException {
        if (this.stmt == null) {
            stmt = con.createStatement();
        }

        return stmt.executeQuery(query);
    }


    private Connection con;
    private Statement stmt;
}