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.
Solved! Go to Solution.
Views
Replies
Total Likes
It looks like you did not configure the DataSourcePool on the AEM Configuratiohn view.
See this article - it steps you through this use case:
https://helpx.adobe.com/experience-manager/using/datasourcepool.html
We also have a HELPX Video so you can watch all of the steps and a working AEM sample (video in table at start of the article)
https://www.youtube.com/watch?v=yYo1epoZp_4&feature=youtu.be
Hope these help you.
Views
Replies
Total Likes
It looks like you did not configure the DataSourcePool on the AEM Configuratiohn view.
See this article - it steps you through this use case:
https://helpx.adobe.com/experience-manager/using/datasourcepool.html
We also have a HELPX Video so you can watch all of the steps and a working AEM sample (video in table at start of the article)
https://www.youtube.com/watch?v=yYo1epoZp_4&feature=youtu.be
Hope these help you.
Views
Replies
Total Likes
Hi
Please have a look at the the Helpx Article,
Link:- https://helpx.adobe.com/in/experience-manager/using/datasourcepool.html
// Injecting a DataSourcePool Service into an Adobe Experience Manager OSGi bundle
This article will give you step by step approach for injecting DataSourcePool.
Another Link:- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets1.html
//Injecting a DataSourcePool into Adobe Experience Manager Sling Servlets
I hope this will help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Many Thanks to Scott MacDonald and Kautuk Sahni for all of their advice on working with Connection Pools in AEM.
The connection pool project to create the bundle is a little awkward to say the least. However, it does now work!!!!!
Thanks again for all the hard work you put into this forum. It is light years ahead of creating a ticket with Adobe to get these things resolved.
-Dean
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies