Using the Informix JDBC Driver and the JDBC Common Client
The section demonstrates how to use the JDBC driver to connect to an Informix® instance.
The JDBC driver demonstration requires the Java™ development kit (JDK). This software component
might not be installed on your image, depending on which virtualization
environment you are using. To determine whether a Java JDK is installed on your system enter the
following command in a terminal window:
javac
If
a Java JDK is installed, usage
information is displayed. If it is not installed, you receive a command
not found message. If a Java JDK
is not installed, you must locate and install a copy to run the tutorial.This example assumes that you are logged into the developer account. Modify the instructions appropriately if you are logged into the informix account.
The sample code assumes that the demo_on instance is up
and running and that the stores database is available. To make sure
that the server is online, type the following in the terminal window:
onstat -
If the server is not online, start it by entering the following
command as user informix:
startDemo
In the steps below, you compile and run a Java program named gentest.java.
- From a terminal window, change to the tutorial directory:
cd ~/Desktop/FirstSteps/Java
- Compile the Java source:
javac gentest.java
- Use the JDBC Common Client to run the program:
java gentest 0
The following output is an example of what might be displayed:Try connecting to stores Connected ... Driver name: IBM DB2 JDBC Universal Driver Architecture Driver version: 3.53.70 Database product name: IDS/UNIX32 Database product version: IFX11700 Prepare and Execute: SELECT * FROM INFORMIX.CUSTOMER WHERE CUSTOMER_NUM = 101 Getting data for row: 1 customer_num: 101 fname: Ludwig lname: Pauli company: All Sports Supplies address1: 213 Erstwild Court address2: null city: Sunnyvale state: CA zipcode: 94086 phone: 408-789-8075 Done
- To use the Informix JDBC
Client to run the program:
java gentest 1
Try connecting to stores Connected ... Driver name: IBM Informix JDBC Driver for IBM Informix Dynamic Server Driver version: 3.50.JC2DE Database product name: Informix Dynamic Server Database product version: 11.70.UC1TL Prepare and Execute: SELECT * FROM INFORMIX.CUSTOMER WHERE CUSTOMER_NUM = 101 Getting data for row: 1 customer_num: 101 fname: Ludwig lname: Pauli company: All Sports Supplies address1: 213 Erstwild Court address2: null city: Sunnyvale state: CA zipcode: 94086 phone: 408-789-8075 Done