The JDBC driver of Informix is type 4.
1. Environment Description
OS: Windows XP
Informix: IDS V10.00.TC1
JDBC: Informix JDBC Embedded SQLJ V2.20JC2
2. JDBC Configuration
After Informix JDBC is installed, add the ifxjdbc. jar path to the CLASSPATH environment variable, for example, CLASSPATH = C: \ ifxjava_home \ lib \ ifxjdbc. jar ;....
The installed directory contains the doc directory, which contains detailed instructions. The demo directory contains the source code for reference.
3. DEMO code
The following source code is for reference (\ Doc \ release \ oij_jdbc_migration.html)
Connect to IDS V10.0 using JDBC in Java
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.exe cuteQuery ("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 ("cocould 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 ();
}
}
}
}