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

package Dao;

import LoginDb.DbHandler;
import java.sql.CallableStatement;
import java.sql.Connection;
import oracle.jdbc.OracleTypes;

/**
 *
 * @author 1004242
 */
public class InsuranceAdditionDao {


     public String createOrUpdateInsurance(String tellerId, String pacsId,String cif ,String insNo,String insDate,String insCompany,String txnType ) {
        Connection con = null;
        CallableStatement proc = null;
        String res = "Request can not be processed";
        int countErr=0;
        System.out.println("createOrUpdateInsurance for user Id :" + tellerId +" ops type:"+txnType);
        try {
             con = DbHandler.getDBConnection();
            proc = con.prepareCall("{ call operations1.POST_CGS_INS(?,?,?,?,?,?,?,?,?) }");

                          proc.setString(1, pacsId);
                          proc.setString(2, tellerId);
                          proc.setString(3, cif);
                          proc.setString(4, insNo);
                          proc.setString(5, insDate);
                          proc.setString(6, insCompany);
                          proc.setString(7, txnType);
                          proc.registerOutParameter(8, OracleTypes.VARCHAR);
                          proc.registerOutParameter(9, OracleTypes.NUMBER);



                          proc.executeUpdate();

                        //  res = proc.getString(8);//error message
                          countErr = proc.getInt(9);//error count

        } catch (Exception e) {
           // e.printStackTrace();
           // System.out.println("Exception occured  in createOrUpdateInsurance for user Id :" + tellerId);
           System.out.println("Error occurred during processing."); 
           res = "Request can not be processed";
        } finally {
            try {
                if (con != null) {
                   // con.commit();
                    con.close();
                }
            } catch (Exception e) {
               // e.printStackTrace();
                System.out.println("Error occurred during connection close.");
            }
        }

        return res;
    }

}
