0

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.

Chandler E.
  • 113
  • 1
  • 11

2 Answers2

1

DB2 can keep the table partially open for a time because it doesn't know when it will be needed again. Another UPDATE might come in the next second, and DB2 wants to avoid a full open for every transaction. As long as this condition continues, you can find a lock contention.

If you encounter such a lock, try the ALCOBJ CONFLICT(*RQSRLS) from your RPG program first, then see if your SaveObject process completes. See the ALCOBJ help text for that parameter for a description of when it can be helpful.

user2338816
  • 2,163
  • 11
  • 11
0

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.

Chandler E.
  • 113
  • 1
  • 11