本文主要介绍了JDBC连接Informix IDS的具体过程,主要包括环境说明、JDBC配置以及演示代码。.... 在安装完后的目录中有doc目录,里面有详细的文档说明。还有demo目录,里面有可以参考的源代码
本文主要介绍了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();
}
}
}
} |