java informix jdbc连接,informix jdbc卡住连接

I'm trying to connect to a Informix database server with jdbc using the standard way :

connection = DriverManager.getConnection("jdbc:informix-sqli://"+ip+

/"+sid+":INFORMIXSERVER="+server+";user="+user+";password="+pass+"");

But it keeps trying to connect and does not throw a error message (I suppose it tries to connect because it does not show anything). I'm using IBM Informix driver 4.10.00.1534 and Java 1.7.

I have been using this method to connect to Informix servers until now, in fact it only fails with one server. I can connect to this server through Informix clients with odbc but it keeps failing with jdbc with no error message.

Is there any method to verbose the jdbc connection? Any suggestion about why it fails?

UPDATE: The sqlidebug trace:

C->S (4)

SQ_VERSION

SQ_EOT

S->C (14)

SQ_VERSION

"7.31.TD6" [8]

SQ_EOT

C->S (66)

SQ_INFO

INFO_ENV

Name Length = 12

Value Length = 8

"DBTIME"="%d/%M/%Y"

"DBTEMP"="/tmp"

"SUBQCACHESZ"="10"

INFO_DONE

SQ_EOT

S->C (2)

SQ_EOT

C->S (16)

SQ_DBOPEN

"database" [8]

NOT EXCLUSIVE

SQ_EOT

S->C (28)

SQ_DONE

Warning..: 0x15

# rows...: 0

rowid....: 0

serial id: 0

SQ_COST

estimated #rows: 1

estimated I/O..: 1

SQ_EOT

C->S (78)

SQ_PREPARE

# values: 0

CMD.....: "select site from informix.systables where tabname = ' GL_COLLATE'" [65]

SQ_NDESCRIBE

SQ_WANTDONE

SQ_EOT

And the jdbctrace.log says:

trying com.informix.jdbc.IfxDriver

SQLWarning: reason(Database selected) SQLState(01I04)

SQLWarning: reason(Float to decimal conversion has been used) SQLState(01I05)

SQLWarning: reason(Database has transactions) SQLState(01I01)

SQLWarning: reason(Database selected) SQLState(01I04)

SQLWarning: reason(Database has transactions) SQLState(01I01)

SQLWarning: reason(Database selected) SQLState(01I04)

解决方案

Try to run code that connects do Informix database but also shows full exception info and create trace files. One trace file is for JDBC, one is for Informix. Change URL to database, username and password, and run it. You will probably see the problem on screen or in trace file:

import java.io.FileWriter;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

class informix_trace

{

public static void main(String[] args)

{

try

{

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

FileWriter fwTrace = new FileWriter("c:\\JDBCTrace.log");

PrintWriter pwTrace = new PrintWriter(fwTrace);

DriverManager.setLogWriter(pwTrace);

String debug_url = "SQLIDEBUG=C:\\sqlidebug.trace";

String url = "jdbc:informix-sqli://1.2.3.4:9088/test_db:informixserver=ol_testifx;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250;" + debug_url

Connection connection = DriverManager.getConnection(url, "user", "passwd");

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery("SELECT FIRST 1 DBINFO('version','full') FROM systables;");

while (resultSet.next())

System.out.println(resultSet.getObject(1));

}

catch (Exception e)

{

e.printStackTrace();

}

}

} // class informix_trace

Informix trace file will be with some postfix (timestamp or similar info) and in my case it was something like sqlidebug.trace1391758523500.0. It is binary but you can analyze it using sqliprt utility.

Example of my session with wrong database name:

c:\>sqliprt sqlidebug.trace1391758523500.0

SQLIDBG Version 1

...

S->C (12)

SQ_ERR

SQL error..........: -329

ISAM/RSAM error....: -111

Offset in statement: 0

Error message......: "" [0]

SQ_EOT

In JDBCTrace.log I can found more interesting info (I see it also on my screen):

SQLState(IX000) vendor code(-111)

java.sql.SQLException: ISAM error: no record found.

at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:413)

at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3412)

at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2324)

....

at java.sql.DriverManager.getConnection(Unknown Source)

at informix_trace.main(informix_trace.java:20)

getConnection failed: java.sql.SQLException: No database found or wrong system privileges.

(I have translated it from Polish so it can be little different)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用Informix JDBC连接数据库,您需要下载相应的JDBC驱动程序,并确保在您的Java项目中包含这些驱动程序的JAR文件。 根据引用,您需要下载以下JAR文件:ifxjdbc.jar,ifxsqlj.jar和ifxtools.jar。您可以在Informix官方网站或相关第三方网站上找到这些JAR文件的下载链接。 一旦您下载了这些JAR文件,您可以按照引用中提供的示例代码来建立JDBC连接。您需要使用一个连接字符串来指定数据库服务器的IP地址、端口号、数据库名称以及其他必要的参数,如用户名和密码。在连接字符串中,您还需要指定Informix服务器的名称(INFORMIXSERVER)。 在您的Java代码中,您需要使用`Class.forName`方法加载Informix JDBC驱动程序,并使用`DriverManager.getConnection`方法来建立与数据库的连接。然后,您可以使用`Connection`对象来创建`Statement`对象,并使用该对象执行SQL查询。 在引用中提供了另一个示例代码,您可以参考该代码来了解如何使用Informix JDBC连接数据库。在该示例代码中,您可以看到使用了不同的连接字符串、用户名和密码。 需要注意的是,在您的代码中,您应该在连接成功后关闭`ResultSet`、`Statement`和`Connection`对象,以及处理可能发生的异常。 综上所述,要使用Informix JDBC连接数据库,您需要下载相应的JAR文件,并按照示例代码建立连接。确保在连接成功后关闭相关对象,并处理可能发生的异常。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值