Informix JDBC Driver Programmer's Guide
Appendix A: Sample Code
Contents
Index
SimpleConnection.java
/***************************************************************************
*
* Title: SimpleConnection.java
*
* Description: Demo a connection to a server (no database specified)
*
* An example of running the program:
*
* java SimpleConnection
* 'jdbc:informix- sqli://emily:1533:informixserver=emily3;user=rdtest;password=test'
*
* Expected result:
*
* >>>Simple Connection test.
* URL = "jdbc:informix- sqli://emily:1533:informixserver=emily3;user=rdtest;password=test"
* >>>End of Simple Connection test.
*
***************************************************************************
*/
import java.sql.*;
import java.util.*;
public class SimpleConnection {
public static void main(String[] args)
{
if (args.length == 0)
{
System.out.println("ERROR: connection URL must be provided in order to run the demo!");
return;
}
String url = args[0];
String testName = "Simple Connection";
Connection conn = null;
System.out.println(">>>" + testName + " test.");
System.out.println("URL = \"" + url + "\"");
try
{
Class.forName("com.informix.jdbc.IfxDriver");
}
catch (Exception e)
{
System.out.println("ERROR: failed to load Informix JDBC driver.");
}
try
{
conn = DriverManager.getConnection(url);
}
catch (SQLException e)
{
System.out.println("ERROR: failed to connect!");
}
try
{
conn.close();
}
catch (SQLException e)
{
System.out.println("ERROR: failed to close the connection!");
}
System.out.println(">>>End of " + testName + " test.");
}
}
Informix JDBC Driver Programmer's Guide
, Version 1.22
Copyright © 1998, Informix Software, Inc. All rights reserved.