no data source with name "testConn" after asking 0 providers (Oracle AEM integration using jdbcpool configs) | Community
Skip to main content
Level 2
August 9, 2021

no data source with name "testConn" after asking 0 providers (Oracle AEM integration using jdbcpool configs)

  • August 9, 2021
  • 2 replies
  • 1205 views

Everytime after the deploying project bundle jdbc pool osgi config need to be resaved manually, or else I am getting the error at DataSourcePool.getDataSource("testConn")
unable to find the datasource with name "testConn", oracle bundle and my project bundles are active, how to make it pick automatically,

DataSourcePool.getDataSource("testConn") will be called everytime when the code attempts connecting to oracle

 

Config Name: com.day.commons.datasource.jdbcpool.JdbcPoolService-archival.config

 

Have tried to get the dataSource on every query exection, but still facing same

 

import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Modified; import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.day.commons.datasource.poolservice.DataSourceNotFoundException; import com.day.commons.datasource.poolservice.DataSourcePool; @Component(service = OracleConnectorService.class, immediate = true) public class OracleConnectorServiceImpl implements OracleConnectorService { private static final Logger LOG = LoggerFactory.getLogger(OracleConnectorServiceImpl.class); @3214626 private DataSourcePool dataSourceService; Connection dbConnection = null; PreparedStatement preStmt = null; ResultSet rs = null; DataSource dataSource = null; @580286 @9182423 public void activate() { try { dataSource = (DataSource) dataSourceService.getDataSource(ArchivalConstants.ORACLE_DATASOURCE); } catch (DataSourceNotFoundException e) { LOG.error("Unable to establish db connections = {} ", e.getMessage()); } } @9944223 public ResultSet getResultSet(PreparedStatement preStmt) { try { rs = preStmt.executeQuery(); return rs; } catch (SQLException e) { LOG.error("get db results error = {} ", e); } return null; } @9944223 public int modifyData(PreparedStatement preStmt) { try { return preStmt.executeUpdate(); } catch (SQLException e) { LOG.error("exception while executing update query {} ", e); } return 0; } @9944223 public PreparedStatement constructStmt(String query) { setDataBaseConnection(); try { if (null != dbConnection) { preStmt = dbConnection.prepareStatement(query); return preStmt; } } catch (SQLException e) { LOG.error("exception while constructing statement {} ", e.getMessage()); } return null; } @9944223 public void closeConnections() { try { if (null != preStmt) preStmt.close(); if (null != rs) rs.close(); if (null != dbConnection) dbConnection.close(); } catch (SQLException e) { LOG.error("Unable to close db connections {} ", e.getMessage()); } } public void setDataBaseConnection() { try { dbConnection = dataSource.getConnection(); if (null != dbConnection) LOG.debug("Connection getMetaData = {} ", dbConnection.getMetaData().getURL()); } catch (SQLException e) { LOG.error("Unable to establish db connections = {} ", e.getMessage()); } } }

 

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

2 replies

Vijayalakshmi_S
Level 10
August 9, 2021

Hi @himanagaudaykiran,

Could you please let know

  • If the OSGi config factory instance of (Day Commons JDBC Connections Pool) is created with unique identifier. If possible, share the config node name you have used.
  • Place where you are instantiating the DB connection (DataSourcePool.getDataSource("testConn") ..) Is it in the activate method ?
Level 2
August 9, 2021
Hi @vijayalakshmi_s, Updated the post with code
arunpatidar
Community Advisor
Community Advisor
August 9, 2021

Hi,

Just wondering in your code below is typo or the annotations are wrong,

it looks like in this thread they are auto changing. But did you try creating repository based configuartion?

 

@activate
   @MODIFIED
   public void activate() {

 e.g.

 

 

/* @580286 @9182423 */

 

 

Arun Patidar
Level 2
August 9, 2021
hi @arunpatidar, saved oracle related data inside file com.day.commons.datasource.jdbcpool.JdbcPoolService-archival.config for specific run modes, Yes @Moadified & @580286 is happening only in this thread