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

package LoginDb;

import java.text.ParseException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author 590685
 */
public class DbConnection {

        public String[] validateUserLogin (String userId, String password, String PacsId) throws SQLException{
        Connection connection = null;
        ResultSet resultset = null;
        Statement statement = null;
        String[] ans = new String[4];

        String ExistPassword = null; // initializatoin changed to null for SAST
        String ipAddress = "";
        String Flag = "";
        String pacs = "";
      
         
        try {

           
            connection =DbHandler.getDBConnection();

            statement = connection.createStatement();

             //look at " for table name
            ResultSet rs = statement.executeQuery("SELECT password, ip_flag, static_ip, pacs_Id FROM login_details where login_id= '" + userId + "' and pacs_id='" + PacsId + "'");
            
            //print the result set
            while (rs.next())
            {
                
            ExistPassword =  rs.getString("password");
            ipAddress =  rs.getString("static_ip");
            Flag = rs.getString("ip_flag");
            pacs = rs.getString("pacs_Id");
            }

            ans[0] = ExistPassword;
            ans[1] = ipAddress;
            ans[2] = Flag;
            ans[3] = pacs;

//            statement.close();
//            connection.close();

        } catch (SQLException ex)
            {
               // ex.printStackTrace();
                System.out.println("Error Occurred during processing.");
            } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if (connection != null)
                    connection.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }

            }
                       
         return ans;
        }

}