Skip to content

Instantly share code, notes, and snippets.

@davidjgonzalez
Created April 7, 2016 08:58
Show Gist options
  • Save davidjgonzalez/f7bcc0a44613255e50873ae02732a8ef to your computer and use it in GitHub Desktop.
Save davidjgonzalez/f7bcc0a44613255e50873ae02732a8ef to your computer and use it in GitHub Desktop.
<%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" contentType="text/html; charset=utf-8"
pageEncoding="UTF-8"
import="org.apache.sling.api.resource.*,
com.day.commons.datasource.poolservice.DataSourcePool,
javax.sql.*,
java.sql.*,
java.util.*,
javax.jcr.*,
com.day.cq.search.*,
com.day.cq.wcm.api.*,
com.day.cq.dam.api.*"%><%
DataSourcePool dspService = sling.getService(DataSourcePool.class);
try {
DataSource ds = (DataSource) dspService.getDataSource("sqlite");
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 assets");
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><%
}
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment