Expand my Community achievements bar.

accessToUnderlyingConnectionAllowed is coming false

Avatar

Level 2

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

3 Replies

Avatar

Employee

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>

  

Avatar

Level 2

thanks @ vanegi for your reply.. When i rechecked everything i found database was down....after restarting it worked. but i have another query that when we put my configuration inside jdbc pool it worked. What i have to import in place of com.day.commons.datasource.poolservice.DataSourcePool to use apache sling data pool service as it was not picking datasource configuration from apache sling pool configurations present inside configMgr. then i use jdbc pool configuration & it is working.

Avatar

Employee
Can you share which specific apache sling pool config you are referring here?