首页    新闻    下载    文档    论坛     最新漏洞    黑客教程    数据库    搜索    小榕软件实验室怀旧版    星际争霸WEB版    最新IP准确查询   
名称: 密码:      忘记密码  马上注册
数据库 :: 数据库

JDBC连接Informix IDS


http://www.gipsky.com/


Informix 的JDBC驱动是type 4的方式

1.环境说明





OS: Windows XP



Informix: IDS V10.00.TC1



JDBC: Informix JDBC Embedded SQLJ V2.20JC2



2.JDBC配置



安装完Informix JDBC后把ifxjdbc.jar路径加到CLASSPATH环境变量中,比如CLASSPATH=C:\ifxjava_home\lib\ifxjdbc.jar;....



在安装完后的目录中有doc目录,里面有详细的文档说明。还有demo目录,里面有可以参考的源代码



3.DEMO代码



下面的源代码,是参考了(\doc\release\oij_jdbc_migration.html)



通过Java使用JDBC连接IDS V10.0



import java.sql.*;



import java.util.*;



public class ifx_con



{



public static void main(String[] args)



{



Connection conn;



String url = "jdbc:informix-sqli://IBM-HENRY:1526/sample:informixserver=ol_henry;user=henry;password=happyday";



System.out.println("Informix JDBC connect test.");



try



{



// Load the Informix JDBC Driver



//DriverManager.registerDriver[1];



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



//Create and open a server/database connection



conn = DriverManager.getConnection(url);



System.out.println("JDBC driver name: " conn.getMetaData().getDriverName());



//Queries that return more than one row



Statement query = null;



ResultSet rs = null;



String st = new String();



try



{



query = conn.createStatement();



rs = query.executeQuery("select * from customer");



while (rs.next())



{



System.out.println(rs.getString(2));



}



rs.close();



query.close();



}



catch (SQLException exce)



{



System.out.println("Caught: " exce.getErrorCode());



}



conn.close();



}



catch (ClassNotFoundException drvEx)



{



System.err.println("Could not load JDBC driver");



System.out.println("Exception: " drvEx);



drvEx.printStackTrace();



}



catch(SQLException sqlEx)



{



while(sqlEx != null)



{



System.err.println("SQLException information");



System.err.println("Error msg: " sqlEx.getMessage());



System.err.println("SQLSTATE: " sqlEx.getSQLState());



System.err.println("Error code: " sqlEx.getErrorCode());



sqlEx.printStackTrace();



sqlEx=sqlEx.getNextException();



}



}



}



}
附注
  1. Driver) Class.forName("com.informix.jdbc.IfxDriver").newInstance(
<< Sybase数据库死锁对策 Informix sysmaster表详解 >>
评分
10987654321
API:
gipsky.com& 安信网络
网友个人意见,不代表本站立场。对于发言内容,由发表者自负责任。

系统导航

 

Copyright © 2001-2010 安信网络. All Rights Reserved
京ICP备14013333号-8