Establishing a ConnectionYou must first establish a connection to an Informix database server or database before you can start sending queries and receiving results in your Java program.
You establish a connection by completing two actions:
Loading Informix JDBC DriverTo load Informix JDBC Driver, use the Class.forName() method, passing it the value
The Class.forName() method loads the Informix implementation of the Driver class, IfxDriver. The IfxDriver class then creates an instance of the driver and registers it with the DriverManager.
Once you have loaded Informix JDBC Driver, you are ready to connect to an Informix database or database server.
Creating a ConnectionTo create a connection to an Informix database or database server, use the DriverManager.getConnection() method. This method creates a Connection object, which is later used to create SQL statements, send them to an Informix database, and process the results.
The DriverManager class keeps track of the available drivers and handles connection requests between appropriate drivers and databases or database servers. The url parameter of the getConnection() method is a database URL that specifies the subprotocol (the database connectivity mechanism), the database or database server identifier, and a list of properties. A second parameter to the getConnection() method, property, is the property list. See "Specifying Environment Variables with the Properties Class" for an example of how to specify a property list. The details of the database URL syntax are described in the next section.
The following code example from the CreateDB.java program shows how to connect to database testDB using Informix JDBC Driver. In the full example, the url variable, described in the preceding example, is passed in as a parameter when the program is run at the command line.
Format of Database URLsInformix JDBC Driver supports database URLs of the following format:
In the preceding syntax:
The following example from the DBConnection.java program shows how to first create a connection to the Informix database server called myserver and then connect to the database testDB later in the Java program using the Statement.executeUpdate() method.
Specifying Environment Variables with the Properties ClassInformix JDBC Driver reads Informix environment variables only from the name-value pairs in the connection database URL or from a connection property list. The driver does not consult the user's environment for any environment variables. Refer to "Supported Informix Environment Variables" for a list of supported Informix environment variables.
To specify Informix environment variables via a property list, use the java.util.Properties class to build the list of properties. The list of properties might include Informix environment variables, such as INFORMIXSERVER, as well as
Supported Informix Environment VariablesThe following table lists the Informix environment variables supported by Informix JDBC Driver.