HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Delivering JDBC-Based Applications"
Vol. 2, Issue 5, p. 44

	

Example code shows how to use multiple connections:

import java.awt.*;
import java.io.*;

public class Sybase2 {
  private static RDriver Syb1, Syb2;
  private static RConnection conn1, conn2;
  private static RStatement stmt1, stmt2;
  private static RResultSet rs1, rs2;

public static void main(String argv[]) {
  System.out.println("simple console application");
  System.out.println("");
  try {
     Syb1 = new RDriver("pc8180");
     Syb2 = new RDriver("pc8180");
  }
  catch (IOException e) {
      System.out.println("Driver" + e);
      return;
  }
  try {
       conn1 = Syb1.connect("user", "password");
       conn2 = Syb2.connect("user", "password");
        }
        catch (IOException e) {
            System.out.println("Error: Connect() " + e);
            return;
        }
   try {
         stmt1 = conn1.createStatement();
         stmt2 = conn2.createStatement();
        }
    catch (IOException e) {
          System.out.println("Error: createStatement()" + e );
          return;
    }
    try { rs1 = stmt1.executeQuery("select * from t_master "); }
   catch (IOException e) {
   System.out.println("Error: executeQuery() " + e );
   return;
   }
        
        String master_series_nm, detail_nm;
        int master_series_id;

        while( rs1.next() ) {

            try {
                master_series_id = rs1.getInt("master_series_id");
            }  catch (IOException e) {
                System.out.println( "Error rs1.getInt('master_series_id')" + e );
               return;
            }

            try {
                master_series_nm = rs1.getString("master_series_nm");
            }  catch (IOException e) {
                System.out.println( "Error rs1.getString('master_series_nm')" + e );
               return;
            }

            System.out.println(activity_series_id + " --> " + activity_series_nm);
            String sql = new String();
            
            sql = "select * from t_detail where master_series_id = " + new Integer(master_series_id).toString(); 
            
                try {
                    rs2 = stmt2.executeQuery(sql);
                }
                catch (IOException e) {
                    System.out.println("Error: executeQuery() " + e );
                    return;
                }
                while( rs2.next() ) {
                    try {
                        detail_nm = rs2.getString("detail_nm");
                    }  catch (IOException e) {
                       System.out.println( "Error rs1.getString('detail_nm')" + e );
                       return;
                    }
                           System.out.println("   --> " + detail_nm);
                }
}
        try {
            rs1.close();
        } catch (IOException e) {
            return;
        }
 System.out.println("(press Enter to exit)");
        try {
            System.in.read();
        } catch (IOException e) {
            return;
        }

  }

}

Example code shows how to update database record:


       connect to database and use executeUpdate() function  .  
  
        try {
stmt.executeUpdate("insert into t_test (col2) values ('test')"  );
        }
        catch (IOException e) {
System.out.println("Error executing SQL:" + e);
            	return;
        }


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.