Search code examples
javaconnectiondb2jndirpg

SaveObject Job Fails on RPG Program Call From Java


I am trying to call an RPG program from Java. I can get the program to run correctly using the DriverManager as follows:

Connection conn = DriverManager.getConnection("jdbc:as400://" + "sys" + "", "username", "pass");
Statement stmt = conn.createStatement();
Boolean sqlBool = stmt.execute("call DB2.PROGRAM");

However...this is not the way that I want to do it. I want to use the JNDI to connect to the 400 and run the program call, as that is the way I do it to run SELECT, UPDATES, DELETES, etc...

Here is the pseudocode that I have so far, and I am having the RPG fail on the SaveObject.

Context context = new InitialContext();
DataSource ds = (DataSource) context.lookup(JNDI_NAME);
Connection conn = datasource.getConnection();
Statement stmt = conn.createStatement();
Boolean sqlBool = stmt.execute("call DB2.PROGRAM");

Is this a problem with the JNDI connection or a problem with the RPG?

Update: It appears that when the SaveObject job goes to work, it says that the table is locked. I am doing inserts and deletes against this table before running the RPG call...any ideas? What would cause a table to still be locked even if I am closing all connections to the database after processing.


Solution

  • Okay so I spent most of yesterday and today going through the code and finally figured out what was happening.

    In Websphere, in the JDBC custom properties there is a variable named: trueAutoCommit. This variable is by default set to FALSE.

    I changed this to true, which allows the transactions to complete individually when ran, and now that I am calling the RPG program using a separate "transaction" it is not locking the table up.