package corbajdbc; import java.util.Properties; import java.sql.*; import org.omg.CORBA.*; import org.omg.CosNaming.*; public class C_Driver implements Driver { CorbaConnectionFactory factoryRef; static { try { DriverManager.registerDriver(new C_Driver()); } catch (Exception e) { e.printStackTrace(); } } public C_Driver() throws org.omg.CORBA.UserException { String[] sArgs; ORB orb; NamingContext namingRoot; NameComponent[] path = new NameComponent[1]; sArgs = new String[4]; sArgs[0] = "-ORBInitialHost"; sArgs[1] = "freon.fsg.com"; sArgs[2] = "-ORBInitialPort"; sArgs[3] = "1080"; // create and initialize the ORB orb = ORB.init(sArgs, null); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); namingRoot = NamingContextHelper.narrow(objRef); // resolve the Object Reference in Naming path[0] = new NameComponent("CORBAJDBC", ""); factoryRef = CorbaConnectionFactoryHelper.narrow(namingRoot.resolve(path)); // call the ConnectionFactory server object and print results System.out.println(factoryRef.sayhello()); } public Connection connect(String sURLGiven, Properties props) throws SQLException { String sURL; String sUser = props.getProperty("user"); String sPassword = props.getProperty("password"); CorbaConnection connectRef; if (!acceptsURL(sURLGiven)) return null; sURL = "jdbc:" + sURLGiven.substring(11); System.out.println("Connecting to \"" + sURL + "\" as \"" + sUser + "\""); connectRef = factoryRef.connect(sURL, sUser, sPassword); System.out.println(connectRef.sayhello()); return new C_Connection(connectRef); } public DriverPropertyInfo[] getPropertyInfo(String sURL, Properties props) {return null;} public boolean acceptsURL(String sURL) throws SQLException {return sURL.startsWith("jdbc:corba:");} public int getMajorVersion() {return 1;} public int getMinorVersion() {return 0;} public boolean jdbcCompliant() {return false;} }