<commit_before><commit_msg>OOSSE SQLAdaptor ready for use<commit_after>/**************************************************************************************************/
//
//  Project : Kalong Bay Guesthouse Reservation and Logistic System
//  Filename : SQLAdaptor.java
//  Author : <NAME>
//  Student No: TP031319
//  Module Code & Title: CE00204-7 Object-Oriented Software Systems Engineering
//  Due Date : 15 July 2013
//
/**************************************************************************************************/
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;

import java.sql.*;

import java.util.List;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.math.BigDecimal;



public class SQLAdaptor
{
    private final static String jdbcDriver = "com.mysql.jdbc.Driver";
    private final static String url = "jdbc:mysql://localhost:3306/kalongbaydb";
    private final static String user = "javauser";
    private final static String pswd = "apiit";
    private static Connection conn = null;

    public static ArrayList query(String sql)
    {
        ArrayList result = null;
        System.out.println(sql);
        try
        {
            //Load JDBC driver and create connection to the database first
            DbUtils.loadDriver(jdbcDriver);
            conn = DriverManager.getConnection(url, user, pswd);

            //Prepare the runner and execute the query
            QueryRunner qRunner = new QueryRunner();
            result = (ArrayList) qRunner.query(conn, sql, new ArrayListHandler());
        }
        catch(SQLException ex)
        {
            Logger lgr = Logger.getLogger(SQLAdaptor.class.getName());
            lgr.log(Level.SEVERE, ex.getMessage(), ex);
        }
        finally
        {
            try
            {
                DbUtils.close(conn);
            }
            catch(SQLException ex)
            {
                Logger lgr = Logger.getLogger(SQLAdaptor.class.getName());
                lgr.log(Level.WARNING, ex.getMessage(), ex);
            }
        }
        return result;
    }

    public static int update(String sql, Object... param)
    {
        int status=0;
        System.out.println(sql);
        try
        {
            //Load JDBC driver and create connection to the database first
            DbUtils.loadDriver(jdbcDriver);
            conn = DriverManager.getConnection(url, user, pswd);

            //Prepare the runner and execute the update
            QueryRunner qRunner = new QueryRunner();
            status = qRunner.update(conn, sql, param);
        }
        catch(SQLException ex)
        {
            Logger lgr = Logger.getLogger(SQLAdaptor.class.getName());
            lgr.log(Level.SEVERE, ex.getMessage(), ex);
        }
        finally
        {
            try
            {
                DbUtils.close(conn);
            }
            catch(SQLException ex)
            {
                Logger lgr = Logger.getLogger(SQLAdaptor.class.getName());
                lgr.log(Level.WARNING, ex.getMessage(), ex);
            }
        }
        return status;
    }
}
{'fraction_non_alphanumeric': 0.14823670053795576, 'fraction_numerical': 0.006873879258816497, 'mean_word_length': 1.9079061685490877, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6367469', 'n_tokens_mistral': 905, 'n_tokens_neox': 864, 'n_words': 208}