新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 数据库 > informix教程 > 正文:解析:教你快速掌握JDBC连接Informix IDS

解析:教你快速掌握JDBC连接Informix IDS

新客网 XKER.COM 2007-09-17 来源: heizhenzhu 收藏本文

本文主要介绍了JDBC连接Informix IDS的具体过程,主要包括环境说明、JDBC配置以及演示代码。

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代码

通过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((Driver) Class.forName

("com.informix.jdbc.IfxDriver").newInstance());

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();

}

}

}

}

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐