2

JT400 - The JDBC connection is working fine when connecting to a IBMi machine from windows machine.

DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
String sysname = "xxx.xxx.xx.xxx";
String xref = "IBMISQLLIB";
String url = "jdbc:as400://" + sysname + ";translate binary=true;prompt=false;naming=sql;libraries=" + xref;

Connection connection = DriverManager.getConnection(url, "USERNAME", "PASSWORD");
print("Connection created successfully");

But fails to create the connection by using the same code - when running the code on the same IBMi machine (by a runnable jar on 'QSH Command Entry'), ERROR:

java.sql.SQLException: The application requester cannot establish the connection. (A remote host refused an attempted connect operation. (Connection refused)) at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:887) at com.ibm.as400.access.JDError.throwSQLException(JDError.java:610) at com.ibm.as400.access.JDError.throwSQLException(JDError.java:568) at com.ibm.as400.access.AS400JDBCConnectionImpl.setProperties(AS400JDBCConnectionImpl.java:3522) at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1430) at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:1280) at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:403) at java.sql.DriverManager.getConnection(DriverManager.java:675) at java.sql.DriverManager.getConnection(DriverManager.java:258)

Any idea what is going wrong now ??

  • because this was working some days back
  • Same code is working on other IBMi servers

Some more details about the IBMi machine are:

  1. No access right issue for the username used in connection profile
  2. No firewall is setup on IBMi machine
  3. TCP/IP configuration is verified as explained - Configuring TCP/IP on IBM i
John Y
  • 14,123
  • 2
  • 48
  • 72
Kishore_2021
  • 645
  • 12
  • 38
  • 2
    I think this is worthy of being re-opened, it seems rather specific to Java running locally on the IBM i. I didn't see any answers on the linked question that might be the OP's issue. I'd be curious if the OP see's the same behavior using the native driver. `com.ibm.db2.jdbc.app.DB2Driver` and `"jdbc:db2://localhost"` could also use `"driver"="native` on the connection properties – Charles Apr 05 '21 at 17:19
  • 1
    @Kishore_2021 - If you see "Reopen" as a choice under the tags, you can vote to reopen your own question. – John Y Apr 06 '21 at 17:20
  • 2
    Also, regardless of whether this question gets reopened, you can try to get help in other places. The best is probably the [midrange.com mailing lists](https://lists.midrange.com/). You will have to subscribe (it's free) and wait for the administrator to enable you before you can post, but he usually responds within a day. I would recommend subscribing to at least [MIDRANGE-L](https://lists.midrange.com/mailman/listinfo/midrange-l), but also whatever else you are interested in. – John Y Apr 06 '21 at 17:29
  • 2
    It seems like [JAVA400-L](https://lists.midrange.com/mailman/listinfo/java400-l) and [OpenSource](https://lists.midrange.com/mailman/listinfo/opensource) might also be directly relevant to you. Another option, which is a bit more hit-or-miss, but when it hits it's immediate, is [Ryver](https://ibmioss.ryver.com/application/signup/members/9tJsXDG7_iSSi1Q). – John Y Apr 06 '21 at 17:34

3 Answers3

4

Is the database host server active? Use WRKACTJOB to see if jobs name QZDASOINIT are running.

If not, try starting the host server with the command STRHOSTSVR *DATABASE.

David G
  • 3,940
  • 1
  • 22
  • 30
1

If you're running your jar file from QSH, you need to make sure that multi-threading is allowed. That could possibly gum things up.

The same code should work just fine if it works on the PC unless you are using a different version of the jt400.jar file possibly as well.

Try using localhost also instead of a system name.

Or even writing a small Java class to open and close a connection.

0

The problem was related to default TCP/IP port, which was not listening the JDBC connection request.

And finally the problem got resolved by restarting the IBMi machine.

:)

Kishore_2021
  • 645
  • 12
  • 38