| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Note: This file is written in Markdown and is best viewed with a Markdown viewer (e.g., GitHub, GitLab, VS Code, or a dedicated Markdown reader). Viewing it in a plain text editor may not render the formatting as intended.
Copyright (c) 2026 Software Tree
This project demonstrates how JDX ORM can invoke database stored procedures and receive their results in an object-oriented way using the jdxHandle.storedProc() API.
Stored procedures are defined in the database independently of JDX ORM. JDX provides a simple mechanism to call them and map their output — whether result sets, scalar values, or update counts — back to Java objects or raw values. The stored procedures and their related tables must be created in the database before running this example. The included StoredProcedures_Script.txt file provides the MySQL DDL statements to do this.
The domain model is a single SimpleAddr (address) class mapped to the SPTest_Address table. Five stored procedures are declared in the ORM mapping file and demonstrated in the application:
| Stored Procedure | Input Parameters | Output |
|---|---|---|
| SP_AllAddresses | None | All SimpleAddr objects |
| SP_AddressesByState | state (String) | SimpleAddr objects matching the state |
| SP_AddressCountByState | state (String) | Count of addresses in the state (scalar) |
| SP_ZipUpdate | addrId, zip (String) | Update count + updated row count |
| SP_Square | number (int) | Square of the number (scalar) |
Important: Unlike other JDX examples, the database schema and stored procedures for this example must be created manually before running the application. JDX does not create stored procedures automatically, and forceCreateSchema is set to false in main() for this reason.
JDX_StoredProceduresExample/ ├── config/ │ └── storedprocedures_example.jdx # ORM mapping specification file ├── src/ │ └── com/softwaretree/jdxstoredproceduresexample/ │ ├── StoredProceduresExample.java # Main application entry point │ └── model/ │ └── SimpleAddr.java # Address model class ├── bin/ # Compiled .class files (generated) ├── sources.txt # List of Java source files for compilation ├── StoredProcedures_Script.txt # MySQL DDL to create the table and stored procedures ├── Overview.txt # High-level overview of using stored procedures with JDX ORM ├── compile.cmd # Windows: compile the Java source files ├── compile.sh # Mac/Linux: compile the Java source files ├── setEnvironment.bat # Windows: sets classpath environment variable ├── setEnvironment.sh # Mac/Linux: sets classpath environment variable ├── runJDXExample.bat # Windows: run the sample application ├── runJDXExample.sh # Mac/Linux: run the sample application ├── forward.bat # Windows: generate schema from the .jdx mapping file ├── forward.sh # Mac/Linux: generate schema from the .jdx mapping file ├── JDXDemo.bat # Windows: launch the JDXDemo GUI application ├── JDXDemo.sh # Mac/Linux: launch the JDXDemo GUI application └── README.md # This file
| Field | Type | DB Column | SQL Type | Notes |
|---|---|---|---|---|
| addrId | String | addrId | VARCHAR(20) | Primary key |
| addr1 | String | addr1 | VARCHAR(255) | |
| addr2 | String | addr2 | VARCHAR(255) | Nullable |
| city | String | city | VARCHAR(255) | |
| state | String | state | VARCHAR(20) | |
| zip | String | zip | VARCHAR(10) | |
| country | String | country | VARCHAR(255) | Nullable |
Unlike most other examples, SimpleAddr in this project uses public fields directly (no private fields with getters/setters), though getters and setters are also present for compatibility.
Contains the MySQL DDL statements to create the SPTest_Address table and the five stored procedures used by this example. Execute this script against your MySQL database before running the application. The stored procedures are written for MySQL 5.7+; adapt them for other databases as needed.
The five stored procedures created are:
This file maps the SimpleAddr class and declares all five stored procedures. Key elements:
Refer to the JDX Database & JDBC Driver Specification Guide for configuring other databases.
Note: Update JDX_DATABASE and JDBC_DRIVER to match your local database setup before running.
The entry point assumes the database table and stored procedures already exist (forceCreateSchema = false). The application:
Results from each storedProc() call are printed using JXUtilities.printSPResults(). For stored procedures declared with SP_CLASS, results are returned as a List of SimpleAddr objects; for others, results are raw scalar values or counts.
Lists all .java source files to be compiled, one per line:
./src/com/softwaretree/jdxstoredproceduresexample/model/SimpleAddr.java ./src/com/softwaretree/jdxstoredproceduresexample/StoredProceduresExample.java
This file is passed to javac using the @sources.txt argument syntax.
Compiles all Java source files listed in sources.txt and outputs .class files into the bin/ directory.
Windows:
compile.cmdMac/Linux:
chmod +x compile.sh # first time only
./compile.shSets the CLASSPATH environment variable to include the JDX ORM libraries and the appropriate JDBC driver JAR. Edit this file to point to the correct JDBC driver for your database before running the application.
Invokes the environment setup script to configure the classpath, then runs the StoredProceduresExample main class.
Windows:
runJDXExample.batMac/Linux:
chmod +x runJDXExample.sh # first time only
./runJDXExample.shGenerates the SPTest_Address table schema from the ORM mapping file. Note that this does not create the stored procedures — those must be created separately using StoredProcedures_Script.txt.
Windows:
forward -createMac/Linux:
chmod +x forward.sh # first time only
./forward.sh -createLaunches the JDXDemo desktop GUI application, which provides a graphical way to browse and interact with the SPTest_Address table and invoke the stored procedures using the JDX ORM configuration.
Windows:
JDXDemo.batMac/Linux:
chmod +x JDXDemo.sh # first time only
./JDXDemo.shSet JX_HOME to the root of your JDX ORM SDK installation.
Configure the database by editing config/storedprocedures_example.jdx:
Create the database table and stored procedures by executing the statements in StoredProcedures_Script.txt against your MySQL database using MySQL Workbench, the MySQL CLI, or another database tool.
Compile the source files:
compile.cmd # Windows
./compile.sh # Mac/LinuxRun the sample application:
runJDXExample.bat # Windows
./runJDXExample.sh # Mac/LinuxMac/Linux tip: Run chmod +x *.sh once in the project directory to make all shell scripts executable.
This project can be imported directly into the Eclipse IDE as an existing Java project using File → Import → Existing Projects into Workspace.
| Back | FazBrowse Home | New Git URL |