Guest User

Untitled

a guest
Jun 30th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. IDENTIFICATION DIVISION.
  2. PROGRAM-ID. connection.
  3. Environment division.
  4.  
  5. input-output section.
  6. file-control.
  7.  
  8. select parameterfile assign to
  9. "parbest.txt"
  10. organization is line sequential
  11. access mode is sequential.
  12.  
  13. select logfile assign to
  14. "logfile.txt"
  15. organization is sequential
  16. access mode is sequential.
  17.  
  18. DATA DIVISION.
  19. File section.
  20. FD logfile.
  21. * linage 60
  22. * with footing at 56
  23. * lines at bottom 3.
  24. * linage mag gebruikt worden in UC 2, maar is hier niet nodig.
  25. 01 logMessage pic x(100).
  26.  
  27. FD parameterfile.
  28. 01 viewingRecord.
  29. 88 end-file value high-values.
  30. 02 readline pic x(100).
  31.  
  32.  
  33. EXEC SQL BEGIN DECLARE SECTION END-EXEC
  34. 77 SQLCODE Pic S9(3).
  35. 77 SQLSTATE Pic X(5).
  36. EXEC SQL END DECLARE SECTION END-EXEC
  37.  
  38.  
  39. * SQLCODE is 0 for success, 100 for no data, -1 for failure
  40. 01 SQLCODE PIC S9(3).
  41.  
  42. * SQLSTATE is a 5 character communication code; 00xxx is success.
  43. 01 SQLSTATE PIC X(5).
  44.  
  45. 01 JdbcString PIC X(255).
  46.  
  47. * EXEC SQL
  48. * END DECLARE SECTION
  49. * END-EXEC
  50.  
  51.  
  52. 01 writingRecord.
  53. 02 login pic x(20).
  54. 02 passw pic x(20).
  55.  
  56.  
  57. PROCEDURE DIVISION.
  58. Pgm.
  59. open output logfile
  60. perform MAIN-PARAGRAPH
  61. perform DO-CONNECT
  62. exit program.
  63.  
  64. MAIN-PARAGRAPH.
  65. * Initial code
  66. PERFORM DO-CONNECT
  67.  
  68. DISPLAY "After connecting to the database:"
  69.  
  70. DISPLAY "SQLCODE= " + SQLCODE.
  71. DISPLAY "SQLSTATE= " + SQLSTATE
  72.  
  73. * Use the database
  74.  
  75. PERFORM DO-DISCONNECT
  76. ACCEPT SQLSTATE
  77. * Terminate the program
  78. GOBACK
  79.  
  80. DO-CONNECT.
  81.  
  82. STRING "jdbc:sqlserver://localhost\SQLEXPRESS;"
  83. DELIMITED BY SIZE
  84. "databaseName=ProjectManagement;"
  85. DELIMITED BY SIZE
  86. "userName=Nelis;password=nelis"
  87. DELIMITED BY SIZE
  88. INTO JdbcString
  89.  
  90. EXEC SQL
  91. CONNECT
  92. TO :JdbcString
  93. DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver"
  94. END-EXEC.
  95.  
  96. if SQLCODE = 0
  97. perform DO-MAIN
  98. else
  99. perform LOG-CONNERR
  100. end-if.
  101. * SQLCODE = 0 IS GOED MAAR AL DE REST IS FOUT DUS ANDERS OPVANGEN
  102.  
  103.  
  104. .
  105. * Disconnect from the SQL database connection. This allows the
  106. * JDBC driver to free any resources required for the connection.
  107.  
  108. DO-DISCONNECT.
  109. EXEC SQL
  110. DISCONNECT
  111. END-EXEC.
  112.  
  113. DO-MAIN.
  114. perform LOG-CONN
  115. open input parameterfile
  116. perform DO-READ
  117.  
  118. perform until end-file
  119. perform READ-LOGINPARS
  120. end-perform
  121. .
  122.  
  123. DO-READ.
  124. READ parameterfile next at end
  125. move high-values to viewingRecord
  126. perform LOG-ISREADBUTEMPTY
  127. END-READ.
  128.  
  129. READ-LOGINPARS.
  130. unstring viewingRecord
  131. delimited by spaces into login, passw
  132. end-unstring
  133.  
  134. perform READ-RECORD
  135. .
  136.  
  137. READ-RECORD.
  138.  
  139. perform READ-LOGIN
  140. perform READ-PASSW
  141. .
  142.  
  143. READ-LOGIN.
  144. EXEC SQL
  145. SELECT login
  146. FROM tgamUsers
  147. INTO :dbLogin
  148. WHERE
  149. END-EXEC.
  150.  
  151.  
  152. LOG-CONN.
  153. move "DATABASE: Connection was made" to logMessage
  154. write logMessage invalid key display 'error'
  155.  
  156. move "Parameterfile is being read.." to logMessage
  157. write logMessage.
  158.  
  159. LOG-CONNERR.
  160. move "DATABASE: Connection could not be made."
  161. to logMessage
  162. write logMessage before advancing 2 lines.
  163.  
  164.  
  165. LOG-ISREADBUTEMPTY.
  166. move "FILE: Read file is empty" to logMessage
  167. write logMessage.
Add Comment
Please, Sign In to add comment