/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package grammar;

import java.io.IOException;
import java.sql.*;
import java.util.*;

/**
 *
 * @author Administrator
 */
public class Recognition {

    public static Vector getResultFor(String sqlFile)
            throws SQLException, IOException
    {        
        String sqlStatement = "";

        Vector resultVect = new Vector();
        try
        {
            ResourceBundle grammarSQLQueries = ResourceBundle.getBundle("grammar.SQLQueries");
            sqlStatement = grammarSQLQueries.getString(sqlFile);

            ResourceBundle config = ResourceBundle.getBundle("config");
            // get a DB connection
            String dbURL = config.getString("dbURL");
            String username = config.getString("username");
            String password = config.getString("password");

            Connection connection = DriverManager.getConnection(dbURL, username, password);
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sqlStatement);

            while (resultSet.next())
            {
                Grammar grm = new Grammar(resultSet.getString(1),resultSet.getString(2));
                resultVect.addElement(grm);
            }

            resultSet.close();
            statement.close();
            connection.close();
        }
        catch(SQLException e)
        {
            //sqlResult = "Error executing the SQL statement: <br>" + e.getMessage();
            return resultVect;
        }

        return resultVect;
    }
}
