| | |
| | | * @throws NamingException when JNDI lookup fails |
| | | */ |
| | | public void setDataSourceName(String dataSourceName) throws NamingException { |
| | | logger.finest(dataSourceName); |
| | | Context initCtx = new InitialContext(); |
| | | Context envCtx = (Context) initCtx.lookup("java:comp/env"); |
| | | ds = (DataSource) envCtx.lookup(dataSourceName); |
| | |
| | | /** |
| | | * Get a database connection |
| | | * @return a database connection |
| | | * @throws SQLException |
| | | */ |
| | | public Connection getConnection() { |
| | | Connection c = null; |
| | | try { |
| | | if (dburl != null) { |
| | | logger.finest("getting Connection for URL " + dburl); |
| | | c = DriverManager.getConnection(dburl); |
| | | } else if(ds != null) { |
| | | logger.finest("getting Connection for DataSource " + ds.toString()); |
| | | c = ds.getConnection(); |
| | | } else { |
| | | //throw new SQLException("Unable to get connection, DataSource and database URL are null."); |
| | | logger.finest("Unable to get connection, DataSource and database URL are null."); |
| | | } |
| | | } catch(Exception ex) { |
| | | ex.printStackTrace(); |
| | | //ex.printStackTrace(); |
| | | logger.log(Level.FINEST, ex.getLocalizedMessage(), ex); |
| | | } |
| | | return c; |
| | | } |