Skip to content

Instantly share code, notes, and snippets.

@dfparker2002
Forked from davidjgonzalez/jdbc.jsp
Created February 26, 2019 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfparker2002/1401c446529746982451ab358596091c to your computer and use it in GitHub Desktop.
Save dfparker2002/1401c446529746982451ab358596091c 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