Expand my Community achievements bar.

SOLVED

AEM 6.2 JSP Connection to a Postgres db

Avatar

Level 1

I am trying to test a quick JSP connection to a postgres db. I was following a tutorial using the Felix Console and uploaded the org.postgresql.jdbc41 jar to the Day Commons JDBC Connections Pool. What I am having trouble figuring out is how exactly to use any of this to connect to the database.

I really just need to grab a simple array of values and need the simplest implementation to get this work.

<%@ page import = "java.sql.*" %>

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %><%@ taglib prefix = "sql" uri="http://java.sun.com/jstl/sql" %>

<%

        Class.forName("org.postgresql.jdbc41");

        Connection con = DriverManager.getConnection("jdbc:postgresql:" + ip, username, pass);

%>

<%

       Statement statement = con.createStatement();

       ResultSet rs = stmt.executeQuery("select * from details");

       while (rs.next()) {  

%>

      <%= rs.getString("address") %>

<%

      }

%>

I understand that I'm doing this incorrectly, but I could really use some help figuring out what I'm doing wrong.

1 Accepted Solution

Avatar

Correct answer by
Level 10
1 Reply

Avatar

Correct answer by
Level 10

See this Article - how to use a DataSourcePool to connect to a database -- Scott's Digital Community: Injecting a DataSourcePool Service into an Adobe Experience Manager OSGi ...