Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDENTIFICATION DIVISION.
- PROGRAM-ID. connection.
- Environment division.
- input-output section.
- file-control.
- select parameterfile assign to
- "parbest.txt"
- organization is line sequential
- access mode is sequential.
- select logfile assign to
- "logfile.txt"
- organization is sequential
- access mode is sequential.
- DATA DIVISION.
- File section.
- FD logfile.
- * linage 60
- * with footing at 56
- * lines at bottom 3.
- * linage mag gebruikt worden in UC 2, maar is hier niet nodig.
- 01 logMessage pic x(100).
- FD parameterfile.
- 01 viewingRecord.
- 88 end-file value high-values.
- 02 readline pic x(100).
- EXEC SQL BEGIN DECLARE SECTION END-EXEC
- 77 SQLCODE Pic S9(3).
- 77 SQLSTATE Pic X(5).
- EXEC SQL END DECLARE SECTION END-EXEC
- * SQLCODE is 0 for success, 100 for no data, -1 for failure
- 01 SQLCODE PIC S9(3).
- * SQLSTATE is a 5 character communication code; 00xxx is success.
- 01 SQLSTATE PIC X(5).
- 01 JdbcString PIC X(255).
- * EXEC SQL
- * END DECLARE SECTION
- * END-EXEC
- 01 writingRecord.
- 02 login pic x(20).
- 02 passw pic x(20).
- PROCEDURE DIVISION.
- Pgm.
- open output logfile
- perform MAIN-PARAGRAPH
- perform DO-CONNECT
- exit program.
- MAIN-PARAGRAPH.
- * Initial code
- PERFORM DO-CONNECT
- DISPLAY "After connecting to the database:"
- DISPLAY "SQLCODE= " + SQLCODE.
- DISPLAY "SQLSTATE= " + SQLSTATE
- * Use the database
- PERFORM DO-DISCONNECT
- ACCEPT SQLSTATE
- * Terminate the program
- GOBACK
- DO-CONNECT.
- STRING "jdbc:sqlserver://localhost\SQLEXPRESS;"
- DELIMITED BY SIZE
- "databaseName=ProjectManagement;"
- DELIMITED BY SIZE
- "userName=Nelis;password=nelis"
- DELIMITED BY SIZE
- INTO JdbcString
- EXEC SQL
- CONNECT
- TO :JdbcString
- DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver"
- END-EXEC.
- if SQLCODE = 0
- perform DO-MAIN
- else
- perform LOG-CONNERR
- end-if.
- * SQLCODE = 0 IS GOED MAAR AL DE REST IS FOUT DUS ANDERS OPVANGEN
- .
- * Disconnect from the SQL database connection. This allows the
- * JDBC driver to free any resources required for the connection.
- DO-DISCONNECT.
- EXEC SQL
- DISCONNECT
- END-EXEC.
- DO-MAIN.
- perform LOG-CONN
- open input parameterfile
- perform DO-READ
- perform until end-file
- perform READ-LOGINPARS
- end-perform
- .
- DO-READ.
- READ parameterfile next at end
- move high-values to viewingRecord
- perform LOG-ISREADBUTEMPTY
- END-READ.
- READ-LOGINPARS.
- unstring viewingRecord
- delimited by spaces into login, passw
- end-unstring
- perform READ-RECORD
- .
- READ-RECORD.
- perform READ-LOGIN
- perform READ-PASSW
- .
- READ-LOGIN.
- EXEC SQL
- SELECT login
- FROM tgamUsers
- INTO :dbLogin
- WHERE
- END-EXEC.
- LOG-CONN.
- move "DATABASE: Connection was made" to logMessage
- write logMessage invalid key display 'error'
- move "Parameterfile is being read.." to logMessage
- write logMessage.
- LOG-CONNERR.
- move "DATABASE: Connection could not be made."
- to logMessage
- write logMessage before advancing 2 lines.
- LOG-ISREADBUTEMPTY.
- move "FILE: Read file is empty" to logMessage
- write logMessage.
Add Comment
Please, Sign In to add comment