SQL/MX Guide to Stored Procedures in Java (G06.24+, H06.03+)

Writing SPJ Methods
HP NonStop SQL/MX Guide to Stored Procedures in Java523727-004
3-8
Referring to Database Objects in an SPJ Method
For information about how to write an SQLJ program, see the SQL/MX Programming
Manual for Java.
Referring to Database Objects in an SPJ Method
In an SPJ method, you can refer to both SQL/MP and SQL/MX database objects, as
you would in other SQL/MX applications. SQL/MX database objects have three-part
ANSI names that include the catalog, schema, and object name. SQL/MP database
objects have Guardian file names that include the node, volume, subvolume, and file
name. SQL/MP aliases, which are three-part logical names, are used to refer to
SQL/MP database objects. For more information about database object names, see
the SQL/MX Reference Manual.
How you qualify three-part object names in an SPJ method depends on the SQL/MX
release that you are using:
Object Name Qualification Before NonStop SQL/MX Release 2.1.1 on page 3-8
Object Name Qualification in NonStop SQL/MX Release 2.1.1 and Later on
page 3-9
Object Name Qualification Before NonStop SQL/MX Release
2.1.1
Before SQL/MX Release 2.1.1 (ABX SPRs), the catalog and schema values of
referenced database objects are not set in the SPJ environment. As a result, you must
fully qualify database objects that are referenced in SPJ methods. This SPJ method
uses the fully qualified object name, SAMDBCAT.SALES.ORDERS:
public static void numDailyOrders(Date date,
int[] numOrders)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:sqlmx:");
PreparedStatement getNumOrders =
conn.prepareStatement("SELECT COUNT(order_date) " +
"FROM samdbcat.sales.orders " +
"WHERE order_date = ?");
getNumOrders.setDate(1, date);
ResultSet rs = getNumOrders.executeQuery();
rs.next();
numOrders[0] = rs.getInt(1);
rs.close();
conn.close();
}
Using fully qualified object names in SPJ methods makes the SPJ methods less
portable from one system to another, where catalog and schema names might differ.
However, if you do not fully qualify the database object names, the default catalog and
schema values will be the same as those in the SYSTEM_DEFAULTS table, which
might be different from the intended catalog and schema.