Connecting to MySQL DataSourcePool is null | Community
Skip to main content
jacobh62502059
New Participant
January 8, 2019
Solved

Connecting to MySQL DataSourcePool is null

  • January 8, 2019
  • 3 replies
  • 1697 views

Hi,

I've been following the tutorial to create a mySQL connection from AEM on AEM 6.2

Adobe Experience Manager Help | Injecting a DataSourcePool Service into an Adobe Experience Manager OSGi bundle

I've created the mySQL bundle that exports com.mysql.jdbc  this includes the com.mysql.jdbc.Driver for the connection

The Database in MySQL workbench is called staff_directory

my Day Commons JDBC Connections Pool config is

JDBC driver class  =  com.mysql.jdbc.Driver

JDBC connection URI  = jdbc:mysql://localhost:3306/staff_directory

Datasource name = Staff

the username and password are both correct

All im trying to do is log out connected to see if the database connection is working. The DataSourcePool variable is always null

@Component

@Service

public class EmployeeServiceImp implements EmployeeService {

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

    

    

   @Reference

   private DataSourcePool source;

   @Override

   public Connection getConnection()

   {

  

            DataSource dataSource = null;

            Connection con = null;

            try

            {

             

                dataSource = (DataSource) source.getDataSource("Staff");

                con = dataSource.getConnection();

                return con;

                log.debug("Connected");

            }

            catch (Exception e)

            {

            log.debug("log error ", e);

            }

                return null;

   }

Thanks for your Help

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

That is an older AEM article for AEM 6.  For community members reading this thread for 6.4 - see this updated one --

Scott's Digital Community: Querying MySQL data using an Adobe Experience Manager 6.4 DataSourcePool

There is a video too showing it working.

For the above problem - did you wrap the JDBC driver file into an OSGi bundle and deploy that?

3 replies

smacdonald2008
New Participant
January 10, 2019

I am glad you got it working. For these type of use cases - I like having videos showing it working in AEM.

jacobh62502059
New Participant
January 9, 2019

Thanks for the help scott, it's all sorted now

smacdonald2008
smacdonald2008Accepted solution
New Participant
January 8, 2019

That is an older AEM article for AEM 6.  For community members reading this thread for 6.4 - see this updated one --

Scott's Digital Community: Querying MySQL data using an Adobe Experience Manager 6.4 DataSourcePool

There is a video too showing it working.

For the above problem - did you wrap the JDBC driver file into an OSGi bundle and deploy that?