Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

DataSource Connection Pool - NPE

Avatar

Level 5

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

        conn = dataSource.getConnection();

    } 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.  

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 10

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. 

Lösung in ursprünglichem Beitrag anzeigen

3 Antworten

Avatar

Korrekte Antwort von
Level 10

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. 

Avatar

Administrator

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



Kautuk Sahni

Avatar

Level 5

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