I am following a course "Learning Path: Enterprise Web Programming with Java" by O'Reilly. I have re-written code for a simple webapp using PostgreSQL. I build it with Maven and run it on a Tomcat server. The database is up and filled. I receive the following error:
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for ${ourDS}"
I have found that it is usually a result of no postgres dependency. I have also tried adding other dependencies like tomcat plugin, etc. I understand that I miss a small piece of dependency or some file somewhere, but I can not find out what is it.
The main .jsp file has a following code:
<%@ page errorPage = "error.jsp" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
<head>
<title>List of products in our database</title>
<link rel = "stylesheet" href = "style.css" type = "text/css"></link>
</head>
<body>
<sql:setDataSource
var = "ourDS"
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:5432/skistuff"
user = "******"
password = "*******"
/>
<sql:query var = "productList" dataSource = "${ourDS}">
SELECT * FROM skisEtc ORDER BY id;
</sql:query>
<!-- Some kind of display -->
</body>
In contrary to the lecturer, I use Maven instead of Ant, so I have to figure it out other way. From what was mentioned in the course, I prepared the following pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.training.skis</groupId>
<artifactId>skispagebasic</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>skispagebasic Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4.jre7</version>
</dependency>
</dependencies>
<build>
<finalName>skispagebasic</finalName>
</build>
</project>