1 21 package com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl; 22 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.sql.DataSource ; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 34 import com.jaspersoft.jasperserver.api.JSExceptionWrapper; 35 36 37 41 public class JndiJdbcDataSourceService extends BaseJdbcDataSource { 42 43 private static final Log log = LogFactory.getLog(JndiJdbcDataSourceService.class); 44 45 private final String jndiName; 46 47 public JndiJdbcDataSourceService(String jndiName) { 48 this.jndiName = jndiName; 49 } 50 51 protected Connection createConnection() { 52 try 53 { 54 Context ctx = new InitialContext (); 55 DataSource ds = (DataSource ) ctx.lookup("java:comp/env/" + jndiName); 56 return ds.getConnection(); 57 } 58 catch (NamingException e) 59 { 60 log.error(e, e); 61 throw new JSExceptionWrapper(e); 62 } 63 catch (SQLException e) 64 { 65 log.error(e, e); 66 throw new JSExceptionWrapper(e); 67 } 68 } 69 70 } 71 | Popular Tags |