DataSource Connection Pool - NPE
I must be doing something wrong, but I'm having trouble figuring it out ......
I'm trying to get a connection to a db connection pool but I get a Null Pointer Exception on the DataSourcePool.
Here is the code:
@Component
@Service(value = DatabaseConnectionImpl.class)
public class DatabaseConnectionImpl {
protected static final Logger log = LoggerFactory.getLogger(DatabaseConnectionImpl.class);
@Reference
private DataSourcePool source;
public Connection getDataBaseConnection(String dataSourceName) {
Connection conn = null;
try {
// SOURCE IS NULL
DataSource dataSource = (DataSource) source.getDataSource(dataSourceName);
// SOURCE IS NULL
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public void executeQuery() {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = getDataBaseConnection("connectionDataSource");
stmt = con.createStatement();
rs = stmt.executeQuery("select abc from table1");
while (rs.next()) {
System.out.println("Jurisdiction=" + rs.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (con != null)
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Any advice is appreciated.