Specify properties

When you use the DriverManager.getConnection() method to create a connection, 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 users environment for any environment variables.

To specify Informix environment variables in the name-value pairs of the connection database URL, see Format of database URLs.

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 user and password.

After you have built the property list, pass it to the DriverManager.getConnection() method as a second parameter. You still need to include a database URL as the first parameter, although in this case you do not need to include the list of properties in the URL.

The following code from the optofc.java example shows how to use the java.util.Properties class to set connection properties. It first uses the Properties.put() method to set the environment variable OPTOFC to 1 in the connection property list; then it connects to the database.

The DriverManager.getConnection() method in this example takes two parameters: the database URL and the property list. The example creates a connection similar to the example given in The DriverManager.getConnection() method.

The following database URL is passed in as a parameter to the example program when the program is run at the command line:
jdbc:informix-sqli://myhost:1533:informixserver=myserver;
   user=rdtest;password=test
The code is:
try
{
   Class.forName("com.informix.jdbc.IfxDriver");
   }
catch (Exception e)
   {
   System.out.println("ERROR: failed to load Informix JDBC driver.");
   }

try
   {
   Properties pr = new Properties();
   pr.put("OPTOFC","1");
   conn = DriverManager.getConnection(newUrl, pr);
   }
catch (SQLException e)
   {
   System.out.println("ERROR: failed to connect!");
   }

Copyright© 2020 HCL Technologies Limited