// DBConnection.java

import java.sql.*;
import java.io.*;

public class DBConnection {
    private Connection conn;

    public DBConnection() {
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            conn = DriverManager.getConnection(
                    "jdbc:mysql://host/DB?autoGenerateTestcaseScript=true",
                    "user","password");
        } catch (Exception e) {
            System.err.println("Exception: " + e);
        }
    }

    public void finalize() {
        System.err.println("Finalizing DBConnection, closing Connection ..");
        dbClose();
    }

    public void dbClose() {
        try {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        } catch (SQLException e) {
            System.err.println("SQLException: " + e.getMessage());
            System.err.println("SQLState:     " + e.getSQLState());
            System.err.println("VendorError:  " + e.getErrorCode());
        }
    }
    
    public Connection getConn() {
        return conn;
    }
}
