// -------------------------------------------------------------------- // Very simple example SQLJ program to connect to more than one // database to do work. // Frank Naude - Oct 2000 // -------------------------------------------------------------------- import sqlj.runtime.*; import sqlj.runtime.ref.*; import java.sql.*; #sql context DB1Ctx; // Define conenction context #sql context DB2Ctx; public class SQLJTst3 { public static void main(String[] args) { Connection c = null; String URL = "jdbc:oracle:thin:@oracle10:1521:acme"; String userid = "acme"; String passwd = "acme"; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to multiple databases DB1Ctx dB1 = new DB1Ctx(DriverManager.getConnection(URL, userid, passwd)); DB2Ctx dB2 = new DB1Ctx(DriverManager.getConnection(URL, userid, passwd)); // Select a row from database DB1 String dBuser1; #sql [dB1] { select user into :dBuser1 from dual }; System.out.println("Database username is " + dBuser1); // Select a row from database DB2 String dBuser2; #sql [dB2] { select user into :dBuser2 from dual }; System.out.println("Database username is " + dBuser2); // Close the database connection #sql { rollback work }; c.close(); System.out.println("Disconected..."); } catch (SQLException e) { e.printStackTrace(); } } }