The process of JDBC connection to Informix IDs

Source: Internet
Author: User
Tags error code informix

This article mainly introduces the process of JDBC connecting to Informix IDs, mainly including environment description, JDBC Configuration and demo code.

1. Environmental description

OS: Windows XP
Informix: IDS V10.00.TC1
JDBC: Informix JDBC Embedded SQLJ V2.20JC2

2.JDBC Configuration

After installing Informix JDBC, add the Ifxjdbc.jar path to the CLASSPATH environment variable, such as

Classpath=c:\ifxjava_home\lib\ifxjdbc.jar;

After the installation of the directory has a doc directory, which has a detailed document description. Also has the demo directory, Inside has can refer to the source code

3.DEMO Code

The following source code, is the reference (\doc\release\oij_jdbc_migration.html)

Using JDBC to connect to IDs via Java 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 ' return to 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 ();
}
}
}
}

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.