1 9 package org.openuss.utility; 10 11 import java.io.*; 12 13 import java.rmi.RemoteException ; 14 15 import java.sql.*; 16 17 import java.util.*; 18 19 21 import javax.naming.*; 22 23 import javax.rmi.*; 24 25 import javax.sql.*; 26 27 29 30 36 public class ConnectionFactory { 37 private static Context initialContext = null; 39 40 47 public static Connection getConnection(String envJdbc) 48 throws Exception { if (initialContext == null) { 51 try { 53 initialContext = new InitialContext(); 54 } catch (Exception e) { 55 System.out.println("Error getting initial context from JNDI: " + 56 e.toString()); 57 } 58 } 59 60 DataSource dataSource = null; 62 63 try { 64 dataSource = (DataSource) initialContext.lookup(envJdbc); 66 67 return dataSource.getConnection(); 69 } catch (Exception e) { 70 System.out.println("Cannot lookup data source " + e.toString()); 71 throw new Exception ("Cannot lookup data source "); } 73 } 74 } | Popular Tags |