//
//    Source File Name: BasicCon.java  1.2 
//  
//   Licensed Materials -- Property of IBM 
//  
//   (c) Copyright International Business Machines Corporation, 1999. 
//       All Rights Reserved. 
//  
//   US Government Users Restricted Rights - 
//   Use, duplication or disclosure restricted by 
//   GSA ADP Schedule Contract with IBM Corp. 
//  
//     PURPOSE : 
//     - demonstrates basic connection to two datasources. 
//     - error handling mostly ignored for simplicity 
//     - refer to MultiCon.java for a more advanced connection program 

//  For more information about these samples, refer to the README file. 

//  For more information on Programming in Java, refer to the  
//  "Programming in Java" section of the Application Development Guide. 

//  For more information on building and running Java programs for DB2, 
//  refer to the "Building Java Applets and Applications" section of the  
//  Application Building Guide. 

//  For more information on the SQL language, refer to the SQL Reference. 

import java.io.*;
import java.lang.*;
import java.sql.*;

class BasicCon {

   static {
      try {
         //  register the driver with DriverManager 
         //  The newInstance() call is needed for the sample to work with 
         //  JDK 1.1.1 on OS/2, where the Class.forName() method does not 
         //  run the static initializer. For other JDKs, the newInstance 
         //  call can be omitted. 
         Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   public static void main (String[] argv) {
      Connection con[] = new Connection[2];  //  two connections allowed 

      try {
         //  connect to the two servers 
         //  see Tools.class on Tools.DBConnect method 
         con[0] = Tools.DBConnect();
         con[1] = Tools.DBConnect();
         con[0].setAutoCommit(false);
         con[1].setAutoCommit(false);

         //  disconnect from the two connections made 
         System.out.println (">Disconnecting...");
         con[0].commit();
         con[1].commit();
         con[0].close();
         con[1].close();
      } catch (Exception e) { e.printStackTrace(); }
   }
}