package com.example.model;

import java.sql.*;

public class SQLUtil {

    // Create connection and statement objects
    
    private Connection myCon;
    private Statement myStmt;

    // The Query constructor

    public SQLUtil() {

    } // end Query()

    // connecter method
    //   Register the database driver and create the database
    //   connection and query statement objects

    void connecter() throws SQLException {
	try {
	        
	    // Register the MySQL database driver
	        
	    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
	        
	    // Create the connection object
	        
	    final String URL=
		"jdbc:mysql://jaguar.cis.udel.edu:8099/fillo"; 
	    final String username="fillo"; //change to YOUR username
	    final String password="e998rj"; //change to YOUR MySQL password
	    // NOT your Unix password !!!!

	    myCon = DriverManager.getConnection(URL, username, password);
	        
	    // Create the statement object for the query

	    myStmt = myCon.createStatement();

	} //* end of try clause

	catch (SQLException sqlEx) {
	    throw sqlEx;
	}
	
	catch (Exception e) {
	    System.err.println(e);
	}

    } // * end of the connecter method

    // select method - create the SQL command string,
    // execute it, and display the results

    ResultSet executeQuery(String myQuery) throws SQLException {

	// Create the SELECT command as a String
	final String select_sql = myQuery;
	
	// Perform the query
	ResultSet result = myStmt.executeQuery(select_sql);

	// Return the results
	return result;
	
    } // executeQuery() method


    // closer method - close the database connection
    void closer () throws SQLException {
	myCon.close();
    } 
    
} // class Query
