// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.



package jblog;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.net.URLEncoder;

/**
 * a simple mysql connection handler class
 *
 * @author Liz Warner
 */

public class MySQLConnector  {

    private static String DBUrl = "jdbc:mysql:///test";
    private Connection conn = null;

    // returns a Statement on successful connection

    public Statement connect()
        throws SQLException, Exception
    {
        // try to make a JDBC connection to the "test" database
        Class.forName("org.gjt.mm.mysql.Driver").newInstance();
        conn = DriverManager.getConnection(DBUrl);
        Statement stmt = conn.createStatement();
        //return the new statement for use by other objects
        return stmt;
    }


    public void disconnect(Statement stmt)
    {
        // close the statement and connection if they exist
        if (stmt != null)
        {
            try
            {
                stmt.close();
            }
            catch (SQLException sqlEx)
            {
                // ignore 
            }
        }
        if (conn != null)
        {
            try
            {
                conn.close();
            }
            catch (SQLException sqlEx) 
            {
                // ignore
            }
        }
    }
}