JDBC connection Informix IDS

Source: Internet
Author: User
Tags informix

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.