accessToUnderlyingConnectionAllowed is coming false

amitcsknit

22-07-2020

I am trying to make connection in mysql database via putting property inside configMgr with jdpc pool configurations

 

datasource is coming from org.apache.commons.dbcp.PoolingDataSource but when i trying to access connection inside is, its null and if i check few attributes , i found one interesting one as accessToUnderlyingConnectionAllowed is coming false

Accepted Solutions (0)

Answers (1)

Answers (1)

vanegi

Employee

22-07-2020

Can you check with the following example JSP code that obtains an instance of the hsqldbds data source, and see if connection is really happening?

 

<%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false"%><%
%><%@ page import="com.day.commons.datasource.poolservice.DataSourcePool" %><%
%><%@ page import="javax.sql.DataSource" %><%
%><%@ page import="java.sql.Connection" %><%
%><%@ page import="java.sql.SQLException" %><%
%><%@ page import="java.sql.Statement" %><%
%><%@ page import="java.sql.ResultSet"%><%
%><html>
<cq:include script="head.jsp"/>
<body>
<%DataSourcePool dspService = sling.getService(DataSourcePool.class);
  try {
     DataSource ds = (DataSource) dspService.getDataSource("hsqldbds"); 
     if(ds != null) {
         %><p>Obtained the datasource!</p><%
         %><%final Connection connection = ds.getConnection();
          final Statement statement = connection.createStatement();
          final ResultSet resultSet = statement.executeQuery("SELECT * from INFORMATION_SCHEMA.SYSTEM_USERS"); 
          int r=0;
          while(resultSet.next()){
             r=r+1;
          } 
          resultSet.close();
          %><p>Number of results: <%=r%></p><%
      } 
   }catch (Exception e) {
        %><p>error! <%=e.getMessage()%></p><%
    } 
%></body>
</html>