package API_GHSC;

import java.sql.*;
import java.net.*;


public class DataAccess {


	private static Connection conn = null;

    public DataAccess() {
        if( conn == null )
        	conn = this.getConnection();
    }


    private static Connection getConnection() {
    	
    	Connection c = null;
    	try
    	{
            Class.forName("org.postgresql.Driver");
	    	String dbUrl = System.getenv("DATABASE_URL");
	    	c = DriverManager.getConnection(dbUrl);
    	}
    	catch( Exception e )
    	{ 
    		System.err.println("DatabaseConnection - Failed");
            System.err.println("Database URL");
            System.err.println(System.getenv("DATABASE_URL"));
    		System.err.println(e.getMessage());
    		System.err.println(e.getStackTrace());
    	}

    	return c;

	}

    public static ResultSet ExecuteQuery(String sql, int Param) 
    {
        if( conn == null )
            conn = DataAccess.getConnection();

        ResultSet rs = null;
        try
        {
            Statement st = conn.createStatement();
            rs = st.executeQuery("SELECT * FROM mytable WHERE columnfoo = 500");
            //PreparedStatement st = conn.prepareStatement(sql);
            //st.setInt(1, Param);
            //rs = st.executeQuery();
            while (rs.next())
            {
               System.err.println("Column 1 returned ");
               System.err.println(rs.getString(1));
            }
            rs.close();
            st.close();
        }
        catch( SQLException e )
        {
            System.err.println("ExecuteQuery - Failed");
            System.err.println(e.getMessage());
            System.err.println(e.getStackTrace());
        }

        return rs;

    }

}

@@ -934,16 +934,68 @@
 ction();
+%0A        if( conn == null )%0A            return null;
 %0A%0A      
@@ -1031,32 +1031,33 @@
   try%0A        %7B%0A
+%0A
             Stat

fix db connection bug