1 16 package scriptella.driver.jndi; 17 18 import scriptella.jdbc.GenericDriver; 19 20 import javax.naming.InitialContext ; 21 import javax.naming.NamingException ; 22 import javax.sql.DataSource ; 23 import java.sql.SQLException ; 24 import java.util.Properties ; 25 26 37 public class Driver extends GenericDriver { 38 @Override 39 protected java.sql.Connection getConnection(String url, Properties props) throws SQLException { 40 if (url == null) { 41 throw new JndiProviderException("JNDI name must be specified in an url attribute of connection element."); 42 } 43 try { 44 InitialContext ctx = new InitialContext (props); 45 DataSource ds = (DataSource ) ctx.lookup(url); 46 return ds.getConnection(); 47 } catch (NamingException e) { 48 throw new JndiProviderException("A problem occured while trying to lookup a datasource with name " + url, e); 49 } 50 51 } 52 } 53 | Popular Tags |