Hi,
Trying to establish connection to oracle from a
servlet (AEM 6.2) , AEM does provide Data Source Pool service and Ia m trying to use that to get the connection (Day Commons Library -
JDBC pool provider for the Data Source Pool (day.commons.datasource.jdbcpool), Version 1.0.24)
I will paste the code below, and this is all the error that I get in my error log. I am trying to understand what is this DirContext
JDBC Connection URI :
jdbc:oracle:thin:@ldap://XXXXXXXXXXXX:3060/AEM_SVC1_L1;cn=OracleContext[/size]
Here is the full error ,
SQLException in getting connection java.sql.SQLRecoverableException: IO Error: JNDI Package failure javax.naming.NotContextException: Not an instance of DirContext, IO Error: JNDI Package failure javax.naming.NotContextException: Not an instance of DirContext
Please let me know if more details needed.
************* Connection Helper class *******************
ublic Connection getConnection(final
String oracleDBConnection ) {
DataSource dataSource = null;
Connection connection = null;
try {
if (null != oracleDBConnection && !oracleDBConnection.isEmpty() && null!= dataSourcePool) {
dataSource = (DataSource) dataSourcePool.getDataSource(oracleDBConnection);
if (dataSource != null) {
connection = dataSource.getConnection();
}
}
************************
Test Servlet *************************************
@Component(label = "test connection", description = "test connection", metatype = true)
@Properties({
@Property(label = "Paths", description = "Servlet Paths.", name = "sling.servlet.paths", value = { "/services/testconnection" }, propertyPrivate = false),
@Property(name = "sling.servlet.methods", value = { "GET", "POST" }, propertyPrivate = true) })
@Service(Servlet.class)
public class TestServlet extends SlingAllMethodsServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
/** The Constant LOG. */
private static final Logger log = LoggerFactory.getLogger(TestServlet.class);
private static final String ORACLE_DATA_SOURCE = "brand";
private static String queryString ="select table_name from all_tables";
/** The query builder. */
@Reference
private ConnectionHelper connectionHelper;
/** @scr.reference policy="static" */
private DataSourcePool dataSourceService;
DataSource dataSource = null;
Connection connection = null;
@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
try {
log.info("DATA_SOURCE -->"+ORACLE_DATA_SOURCE);
connection = connectionHelper.getConnection(ORACLE_DATA_SOURCE);
log.info("connection-->"+connection);
//dataSource = (DataSource) dataSourceService.getDataSource("brand");
final ResultSet resultSet = connection.createStatement().executeQuery(queryString);
log.info("ResultSet : " + resultSet);
} catch (Exception e) {
log.error("Exception from DOGET in test servelt {}", e.getStackTrace());
e.printStackTrace();
//e.getStackTrace();
} finally {
if(null!=connection){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}