查找与 iSeries 的特定 JDBC SQL 连接的实际作业号?

发布于 2024-09-14 18:34:53 字数 198 浏览 7 评论 0原文

我正在使用 JTOpen JDBC 驱动程序连接到 iSeries(又名 AS/400、IBM System-i、IBMi、WTH?!...)。我在使用特定语句时遇到问题,看来我需要返回到实际的 SQL 作业 QSQSRVR(或 QZDASOINIT?)以查找更多详细信息。唯一的问题是系统上有数百个这样的东西。有没有一种简单的方法来确定实际处理我的 SQL 连接或特定语句的作业?

I am using the JTOpen JDBC driver to connect to the iSeries (aka AS/400, IBM System-i, IBMi, WTH?!...). I am having problems with a particular statement and it appears I need to go back to the actual SQL job QSQSRVR (or QZDASOINIT?) to find more details. Only problem is that there are hundreds of these on the system. Is there an easy way to determine the job which is actually handling my SQL connection or a particular statement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

姐不稀罕 2024-09-21 18:34:53

来自 AS400JDBCConnectionHandle 类的 JT400 javadoc :

获取服务器作业标识符

公共字符串 getServerJobIdentifier()
抛出 SQLException

返回与此对应的主机服务器作业的作业标识符

连接。每个 JDBC 连接都是
与主机服务器作业关联
系统。格式为:

 * 10 个字符的作业名称
    * 10个字符的用户名
    * 6 个字符的职位编号 

注意:由于该方法没有在 JDBC Connection 中定义

接口,通常需要强制转换
返回的 Connection 对象
PooledConnection.getConnection() 到
AS400JDBCConnectionHandle 以便
调用这个方法:

 String serverJobIdentifier = ((AS400JDBCConnectionHandle)connection).getServerJobIdentifier();


返回:
    服务器作业标识符,如果未知则为 null。 
投掷:
    SQLException - 如果连接未打开。

From the JT400 javadoc of the class AS400JDBCConnectionHandle :

getServerJobIdentifier

public String getServerJobIdentifier()
throws SQLException

Returns the job identifier of the host server job corresponding to this

connection. Every JDBC connection is
associated with a host server job on
the system. The format is:

    * 10 character job name
    * 10 character user name
    * 6 character job number 

Note: Since this method is not defined in the JDBC Connection

interface, you typically need to cast
a Connection object returned from
PooledConnection.getConnection() to an
AS400JDBCConnectionHandle in order to
call this method:

      String serverJobIdentifier = ((AS400JDBCConnectionHandle)connection).getServerJobIdentifier();


Returns:
    The server job identifier, or null if not known. 
Throws:
    SQLException - If the connection is not open.
空名 2024-09-21 18:34:53

如果远程应用程序无法修改,则服务器端有几种可能性。最常见的方法是搜索锁定通过连接登录的用户配置文件 (*USRPRF) 的作业。当用户配置文件在作业中处于活动状态时,系统不允许将其删除,因此锁定很方便:

WRKOBJLCK logonuser *USRPRF

连接本身也很有用。 NETSTAT 命令可以列出连接:

NETSTAT *CNN

可以根据列出的服务检查远程 IP 地址以确定特定连接。可以从那里访问匹配的系统作业。

If the remote app can't be modified, there are a couple possibilities on the server side. The most common method is to search for jobs that have a lock on the user profile (*USRPRF) that logged on through a connection. The system won't allow a user profile to be deleted while it's active in a job, so the lock can be handy:

WRKOBJLCK logonuser *USRPRF

The connection itself can also be useful. The NETSTAT command can list connections:

NETSTAT *CNN

The remote IP address can be checked against the listed services to determine the particular connection. The matching system job can be accessed from there.

故事↓在人 2024-09-21 18:34:53

如果您不使用连接池,以下方法会更安全(不知道为什么不池化连接:),但是...)

public static String getQualifiedJobNumber(Connection connection) throws SQLException, CustomException {
    if (connection != null && !connection.isClosed()) {
        String jobName = null;
        try {
            AS400JDBCConnectionHandle handle = ((AS400JDBCConnectionHandle) connection);
            if (handle != null) {
                jobName = handle.getServerJobIdentifier();
            }
        } 
        catch (ClassCastException e) {
            try {
                AS400JDBCConnection as400Connection = ((AS400JDBCConnection) connection);
                if (as400Connection != null) {
                    jobName = as400Connection.getServerJobIdentifier();
                }
            }
            catch (ClassCastException e2) {
                throw new CustomException("Attempting to retrieve an AS400 qualified job number from a non-AS400 connection");
            }
        }
        if (jobName != null && jobName.length() == 26) {
            return jobName.substring(20) + "/" + jobName.substring(10, 20).trim() + "/" + jobName.substring(0, 10).trim();
        }
    }
    return null;
}

The following approach is safer in case you are not using connection pooling (no idea why you wouldn't pool your connections :), but...)

public static String getQualifiedJobNumber(Connection connection) throws SQLException, CustomException {
    if (connection != null && !connection.isClosed()) {
        String jobName = null;
        try {
            AS400JDBCConnectionHandle handle = ((AS400JDBCConnectionHandle) connection);
            if (handle != null) {
                jobName = handle.getServerJobIdentifier();
            }
        } 
        catch (ClassCastException e) {
            try {
                AS400JDBCConnection as400Connection = ((AS400JDBCConnection) connection);
                if (as400Connection != null) {
                    jobName = as400Connection.getServerJobIdentifier();
                }
            }
            catch (ClassCastException e2) {
                throw new CustomException("Attempting to retrieve an AS400 qualified job number from a non-AS400 connection");
            }
        }
        if (jobName != null && jobName.length() == 26) {
            return jobName.substring(20) + "/" + jobName.substring(10, 20).trim() + "/" + jobName.substring(0, 10).trim();
        }
    }
    return null;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文