package UK.co.demon.xinit.jdbc;

/**
 * File		: JdbcDataBase
 * 
 * Sccs		: %W% 
 *
 * Dated	: %D% %T% 
 *
 * Owner	: 
 *
 * Continuus
 * 
 * Type		: %cvtype: %
 * Created by	: %created_by: %
 * Date Created	: %date_created: %
 * Date Modified: %date_modified: %
 * Derived by	: %derived_by: %
 * File/Version	: %filespec: %
 *
 */

import UK.co.demon.xinit.jdbc.*;

import java.sql.*;
import java.util.*;


class
JdbcDatabase
    implements ConnectJdbcInterface
{
    protected String jdbc_driver = null;
    protected String jdbc_url = null;
    protected String jdbc_description = null;

    protected String dburl = null;
    protected Connection connection = null;


    public 
    Connection
    connect(String server, String port, String db, String id, String pw)
	throws Exception
    {
	try {
	    Class.forName (jdbc_driver);
	}
	catch(Exception e) {
	    System.err.println("E%M%_%C% Cannot find driver for" + jdbc_driver + "[" + e + "]");
	    throw e;
        }

	dburl = jdbc_url + server + ":" + port + "/" + db;

	System.out.println("I_connect: Connecting to " + jdbc_description + "[" + dburl + "]");

	try {
	    connection = DriverManager.getConnection(dburl, id, pw);
	} 
	catch(Exception e) { 
	    System.err.println("JdbcDatabase.connect [" + e + "]");
	    throw e;
        }

	return connection;
    }


    public 
    void 
    disconnect(Connection connection) 
	throws Exception 
    {
	try {
	    System.out.println("Closing connection");
	    connection.close();
	    connection = null;
	}
	catch (Exception e) { 
	    System.err.println("closeConnection" + e);
	    throw e;
        }
    }
}



Last Updated