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) |
- Java JDK 8 or higher installed and on the system PATH.
- JDX ORM SDK installed. Set the environment variable
JX_HOMEto the SDK's top-level installation directory. - MySQL database with the stored procedures and
SPTest_Addresstable already created. UseStoredProcedures_Script.txtto create them (see Getting Started below).
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
forceCreateSchemais set tofalseinmain()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:
SP_AllAddresses()—SELECT * FROM SPTest_Address— returns all rows.SP_AddressesByState(IN p_state)— returns rows wherestate = p_state.SP_AddressCountByState(IN p_state)— returnsCOUNT(addrId)for the given state.SP_ZipUpdate(IN p_id, IN p_zip)— updates the zip for a given address ID and returnsROW_COUNT().SP_Square(IN p_number)— returnsp_number * p_number.
This file maps the SimpleAddr class and declares all five stored procedures. Key elements:
JDX_DATABASEandJDBC_DRIVER— pre-configured for MySQL. Update these to match your local setup.JDX_OBJECT_MODEL_PACKAGE— the base Java package for model classes.CLASS .SimpleAddr TABLE SPTest_Address— maps to theSPTest_Addresstable withPRIMARY_KEY addrId, explicitSQLTYPEforaddrIdandzip, andNULLABLEforaddr2andcountry.STORED_PROC SP_AllAddresses/SP_AddressesByState— declared withSP_CLASS .SimpleAddr, telling JDX to map the result set rows back toSimpleAddrobjects.STORED_PROC SP_AddressCountByState/SP_ZipUpdate/SP_Square— declared withoutSP_CLASS; their results are returned as raw scalar values or update counts.
Refer to the JDX Database & JDBC Driver Specification Guide for configuring other databases.
Note: Update
JDX_DATABASEandJDBC_DRIVERto match your local database setup before running.
The entry point assumes the database table and stored procedures already exist (forceCreateSchema = false). The application:
- Deletes all existing
SimpleAddrobjects fromSPTest_Address. - Inserts 5
SimpleAddrobjects usingjdxHandle.insert(list, ...). - Queries all objects with a standard
jdxHandle.query()call to verify the data. - Invokes stored procedures using
jdxHandle.storedProc(name, paramList, ...):SP_AllAddresses— no parameters; returns allSimpleAddrobjects.SP_AddressesByState("CA")— returnsSimpleAddrobjects for California.SP_AddressCountByState("NY")— returns the count of addresses in New York.SP_ZipUpdate("SPTestId1", "12345")— updates the zip for addressspTestId1and returns the row count.SP_Square(5)— returns25.
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.
- Requires
JX_HOMEto be set to the JDX ORM SDK installation directory. - Links against
jxclasses.jar(JDX ORM library) andjson-20240303.jar(JSON support). compile.cmd— Windows batch script (supports JDK 8; a commented line supports JDK 9+).compile.sh— Mac/Linux shell script equivalent.
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.
setEnvironment.bat— Windows (uses;as classpath separator).setEnvironment.sh— Mac/Linux (uses:as classpath separator; sourced viasource ./setEnvironment.sh).
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.sh-
Set
JX_HOMEto the root of your JDX ORM SDK installation. -
Configure the database by editing
config/storedprocedures_example.jdx:- Update
JDX_DATABASEwith the correct MySQL connection URL and credentials. - Update
JDBC_DRIVERif using a different MySQL driver version. - Update
setEnvironment.bat(Windows) orsetEnvironment.sh(Mac/Linux) to include the JDBC driver JAR on the classpath.
- Update
-
Create the database table and stored procedures by executing the statements in
StoredProcedures_Script.txtagainst your MySQL database using MySQL Workbench, the MySQL CLI, or another database tool. -
Compile the source files:
compile.cmd # Windows ./compile.sh # Mac/Linux
-
Run the sample application:
runJDXExample.bat # Windows ./runJDXExample.sh # Mac/Linux
Mac/Linux tip: Run
chmod +x *.shonce 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.
Overview.txt— a brief conceptual overview of how JDX ORM works with stored procedures (included in this directory).- JDX Database & JDBC Driver Specification Guide
- JDX ORM SDK User Manual — see the Stored Procedures chapter for full details on
STORED_PROC,SP_CLASS, parameter passing, and result handling.