SHARE
TWEET

Untitled

a guest Jul 1st, 2018 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        IDENTIFICATION DIVISION.
  2.         PROGRAM-ID. connection.
  3.        
  4.        ENVIRONMENT DIVISION.        
  5.         Input-output section.
  6.          file-control.
  7.  
  8.           select parameterfile
  9.            assign to "parbest.txt"
  10.            organization is line sequential
  11.            access mode is sequential.
  12.        
  13.           select logfile assign to "logfile.txt"
  14.            organization is sequential
  15.            access mode is sequential.
  16.        
  17.        DATA DIVISION.
  18.         File section.
  19.          FD logfile.
  20.       *   linage 60
  21.       *   with footing at 56
  22.       *   lines at bottom 3.    
  23.       *   linage mag gebruikt worden in UC 2, maar is hier niet nodig.  
  24.          01 logMessage   pic x(100).
  25.        
  26.         FD parameterfile.
  27.          01 viewingRecord.
  28.           88 end-file    value high-values.
  29.           02 readline    pic x(1000).
  30.          
  31.          
  32.         EXEC SQL BEGIN DECLARE SECTION END-EXEC
  33.           77 SQLCODE     pic S9(3).
  34.           77 SQLSTATE    pic x(5).      
  35.         EXEC SQL END DECLARE SECTION END-EXEC
  36.       * SQLCODE is 0 for success, 100 for no data, -1 for failure
  37.         01 SQLCODE       pic S9(3).
  38.       * SQLSTATE is a 5 character communication code; 00xxx is success.
  39.         01 SQLSTATE      pic x(5).
  40.        
  41.        
  42.         Working-storage section.
  43.          01 endOfFile    pic x.
  44.          01 inputString  pic x(255).
  45.          01 email        pic x(100).
  46.          01 name         pic x(50).
  47.          01 firstName    pic x(50).
  48.          01 pass         pic x(100).
  49.    
  50.        
  51.        PROCEDURE DIVISION.
  52.         Pgm.    
  53.          open output logfile      
  54.          open input parameterfile        
  55.       * Initial read of parameterfile
  56.          read parameterfile next at end
  57.           move high-values to viewingRecord
  58.           perform LOG-EMPTYFILE
  59.           perform EXITPROGRAM
  60.          end-read.
  61.          move readline to inputString
  62.       * Test read string
  63.          display inputString        
  64.          
  65.          perform CONNECT        
  66.          if SQLCODE = 0
  67.           perform LOG-CONNECTION
  68.       *  Read email, name, firstName & pass
  69.           perform READPARAMETERFILE
  70.           unstring readline delimited by " " into
  71.            email name firstName pass
  72.           end-unstring  
  73.       *  Read & execute SQL instructions      
  74.           perform until end-file
  75.            perform READPARAMETERFILE
  76.            move readline to inputString
  77.            EXEC SQL
  78.             EXECUTE IMMEDIATE :inputString
  79.            END-EXEC
  80.           end-perform
  81.           EXEC SQL
  82.            COMMIT
  83.           END-EXEC
  84.           EXEC SQL
  85.            DISCONNECT
  86.           END-EXEC  
  87.          else
  88.       *  TODO: Specifieke fouten loggen.
  89.           perform LOG-CONNECTIONERROR
  90.          end-if.        
  91.        
  92.         perform EXITPROGRAM.
  93.        
  94.       * PROCEDURES  
  95.         READPARAMETERFILE.
  96.          read parameterfile next at end
  97.           move high-values to viewingRecord
  98.           perform LOG-ENDOFFILE
  99.          end-read.        
  100.        
  101.         CONNECT.      
  102.          EXEC SQL
  103.           CONNECT TO :inputString      
  104.           DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver"                
  105.          END-EXEC.
  106.          
  107.         EXITPROGRAM.
  108.          close logfile
  109.          close parameterfile        
  110.          exit program.
  111.        
  112.          
  113.       * LOG PROCEDURES    
  114.         LOG-EMPTYFILE.
  115.          move "ERROR FILE      : Read file is empty" to logMessage
  116.          write logMessage.
  117.          
  118.         LOG-CONNECTION.
  119.          move "STATUS DATABASE : Connection was made" to logMessage
  120.          write logMessage      
  121.          move "STATUS FILE     : Parameterfile is being read.."
  122.           to logMessage
  123.          write logMessage.
  124.        
  125.         LOG-CONNECTIONERROR.
  126.          move "ERROR DATABASE  : Connection could not be made."
  127.           to logMessage
  128.          write logMessage.      
  129.        
  130.         LOG-ENDOFFILE.
  131.          move "STATUS FILE     : End of file." to logMessage
  132.          write logMessage.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top