Skip to content

feat: Add Java equivalent of COBOL SQL example program (PostgreSQL account handler)#81

Open
devin-ai-integration[bot] wants to merge 5 commits intomainfrom
devin/1776972066-java-migration-consolidated
Open

feat: Add Java equivalent of COBOL SQL example program (PostgreSQL account handler)#81
devin-ai-integration[bot] wants to merge 5 commits intomainfrom
devin/1776972066-java-migration-consolidated

Conversation

@devin-ai-integration
Copy link
Copy Markdown

Summary

Adds a complete Java port of the existing COBOL SQL example program (sql/sql_example.cbl) under a new sql/java/ directory. The Java version provides identical functionality — connecting to the cobol_db_example PostgreSQL database and offering an interactive console menu to display all accounts, display disabled accounts, and search accounts by name/phone/address.

New files:

  • Account.java — POJO mirroring the COBOL ws-account-record structure (8 fields)
  • AccountHandler.java — JDBC connection lifecycle + three query methods mirroring the COBOL cursors (ACCOUNT-ALL-CUR, ACCOUNT-DISABLED-CUR, ACCOUNT-QUERY-CUR), plus tabular display output
  • Main.java — Interactive menu loop replicating the COBOL main-procedure (menu selection, search-again sub-loop, connect-on-start / disconnect-on-exit)
  • sql/java/README.md — Prerequisites, compile/run instructions, connection config

Updated: sql/README.md — added cross-reference to the new Java implementation.

All queries use PreparedStatement. Error handling prints SQL state/code/message matching the COBOL check-sql-state pattern. Connection failure calls System.exit(1) mirroring the COBOL stop run.

Review & Testing Checklist for Human

  • End-to-end test (most important): Stand up PostgreSQL, run create_test_db.sql, compile with the JDBC driver on classpath (javac -cp .:postgresql-*.jar *.java), then run java -cp .:postgresql-*.jar Main and exercise all 4 menu options. Verify output matches the COBOL program.
  • Verify displayAccounts column widths against the COBOL display-account-results paragraph (lines 400–430 of sql_example.cbl). The printf format strings should produce aligned columns matching the COBOL fixed-width output.
  • Verify SQL queries match the three COBOL cursor declarations exactly (lines 118–153 of sql_example.cbl) — same columns, same ORDER BY, same WHERE clauses.
  • searchAccounts(null) produces "%null%" rather than throwing — acceptable for this demo scope, but confirm this is fine.
  • README says JDK 17+ but code compiles on JDK 11 with no post-Java-8 features — decide if the prerequisite should be relaxed.

Notes

Link to Devin session: https://app.devin.ai/sessions/2391de1faa624377bb458732ddb38350
Requested by: @Colhodm

devin-ai-integration Bot and others added 5 commits April 23, 2026 19:17
Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
- Add Account.java POJO with fields: id, firstName, lastName, phone, address, isEnabled, createDt, modDt
- Add AccountHandler.java JDBC handler with connect/disconnect, getAllAccounts, getDisabledAccounts, searchAccounts, displayAccounts
- Add Main.java with interactive console menu replicating COBOL program's menu-driven interface
  - Display all accounts
  - Display disabled accounts
  - Query/search accounts with repeat search loop
  - Exit with graceful disconnect

Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@devin-ai-integration
Copy link
Copy Markdown
Author

End-to-End Test Results

Ran the Java program locally against PostgreSQL 14 with 11-row test dataset. All menu options exercised.

All 9 tests passed
# Test Result
1 Startup & DB connection PASSED
2 Display all accounts (option 1) — 11 rows, ordered by ID PASSED
3 Display disabled accounts (option 2) — 3 rows, all Enabled=N PASSED
4 Search "John" (option 3) — 1 exact match PASSED
5 Search "St" — partial match, all 11 rows returned PASSED
6 Search "ZZZZZ" — no match, zero data rows PASSED
7 Decline search again ("N") — returns to menu PASSED
8 Invalid menu option ("9") — error message shown PASSED
9 Exit (option 4) — "Disconnected.", exit code 0 PASSED
Full output
COBOL SQL DB Example Program - Java Edition
--------------------------------------------
Connected to database.

1) Display all accounts
2) Display disabled accounts
3) Query accounts
4) Exit
Selection: 
ACCOUNTS:

 ID    | First    | Last     | Phone      | Address                | Enabled
------|----------|----------|------------|------------------------|---------
 1     | John     | Tester   | 15555550100 | 123 Fake St, Nowhere   | Y
 2     | Mike     | Tester1  | 15555550121 | 122 Real St, Nowhere   | Y
 3     | Mary     | Tester2  | 15555550132 | 121 ABC St, Nowhere    | Y
 4     | Jack     | Tester3  | 15555550143 | 120 Rock St, Nowhere   | Y
 5     | Bob      | Tester4  | 15555550154 | 119 Truck St, Nowhere  | N
 6     | Paula    | Tester5  | 1555550165 | 118 Car St, Nowhere    | N
 7     | James    | Tester6  | 1555550176 | 117 Land St, Nowhere   | Y
 8     | Jane     | Tester7  | 1555550187 | 116 Sea St, Nowhere    | Y
 9     | Bill     | Tester8  | 1555550198 | 115 Dock St, Nowhere   | N
 10    | Lucy     | Tester9  | 1555550209 | 114 Beach St, Nowhere  | Y
 11    | Richard  | Tester10 | 1555550210 | 113 Water St, Nowhere  | Y

Selection: 
ACCOUNTS:

 ID    | First    | Last     | Phone      | Address                | Enabled
------|----------|----------|------------|------------------------|---------
 5     | Bob      | Tester4  | 15555550154 | 119 Truck St, Nowhere  | N
 6     | Paula    | Tester5  | 1555550165 | 118 Car St, Nowhere    | N
 9     | Bill     | Tester8  | 1555550198 | 115 Dock St, Nowhere   | N

Selection: Enter search value: 
ACCOUNTS:
 1     | John     | Tester   | 15555550100 | 123 Fake St, Nowhere   | Y
Search again? (Y/[N]) Enter search value: 
ACCOUNTS: [11 rows - all addresses contain "St"]
Search again? (Y/[N]) Enter search value: 
ACCOUNTS: [0 data rows]
Search again? (Y/[N]) 

Selection: Please make a selection between 1-4

Selection: Disconnected.
EXIT_CODE: 0

Devin session

Copy link
Copy Markdown

@Colhodm Colhodm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant