0

我正在使用 JDBC 通过 连接到 Informix 实例DriverManager.getConnection method,但我遇到了问题。

DriverManager.getConnection与 Informix 建立连接需要很长时间。我正在尝试解决这个问题,但到目前为止还没有成功。

如何解决这个问题呢?

4

2 回答 2

1

您可以编写简单的测试来显示连接到数据库需要多长时间。对于这样的事情,我喜欢可以与 JDBC 一起使用的 Jython,它可以与本机 JDBC 驱动程序一起使用,并且通过 JDBC-ODBC 桥可以与 ODBC 驱动程序一起使用。当然你必须先配置这样的 ODBC 连接。

这是显示此类时间的测试程序:

import sys
import traceback
import time

from java.sql import DriverManager
from java.lang import Class

Class.forName("com.informix.jdbc.IfxDriver")

def test_conn(db_url, usr, passwd):
    try:
        t0 = time.time()
        try:
            db = DriverManager.getConnection(db_url, usr, passwd)
            t2 = time.time()
            print('%s' % (db_url))
            print('%s, connection time %.03f [s]\n' % (db, (t2-t0)))
        finally:
            db.close()
    except:
        print("there were errors!")
        s = traceback.format_exc()
        sys.stderr.write("%s\n" % (s))


def main():
    for _ in range(5):
        test_conn('jdbc:informix-sqli://169.0.5.10:9088/test:informixserver=ol_t1;', 'user', 'passwd')
        test_conn('jdbc:odbc:ifx_test', 'user', 'passwd')

main()

我的机器上的结果显示 JDBC 在连接方面比 JDBC-ODBC 桥更快(您必须知道桥会增加一些本地应用程序不需要的时间)。此外,我的测试是在 Windows 上运行的,最小分辨率time.time()可能约为 15 毫秒。我的结果:

jdbc:informix-sqli://169.0.5.10...
com.informix.jdbc.IfxSqliConnect@1658cfb, connection time 0.015 [s]

jdbc:odbc:test
sun.jdbc.odbc.JdbcOdbcConnection@ad75b, connection time 0.047 [s]

当然,使用这个程序,您可以测试相同的驱动程序,但使用不同服务器上的数据库。

于 2013-04-19T07:50:37.067 回答
0

The problem can be that your hosts file does not contains the mapping for 127.0.0.1 localhost.

Also it could be a strange behavior of Informix using IPv6 address for port listening that I described on this other SO post: informix jdbc stuck connecting

于 2016-08-13T23:52:38.183 回答