0

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>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    Possible duplicate of https://stackoverflow.com/questions/15913253/no-suitable-driver-found-postgres-jdbc?rq=1 – Ivan Pronin Aug 10 '17 at 20:50
  • Does the error literally contain _"No suitable driver found for **${ourDS}**"_? If so, it seems you have a configuration error – Mark Rotteveel Aug 11 '17 at 09:08
  • I have copied the exception directly from the server response ("error.jsp"). I have followed the thread linked here. I have added the resource parts in web.xml file of my application and in the context.xml file in tomcat/conf directory. Stil, I get the same exception. – Paweł Grabiński Aug 16 '17 at 19:06

0 Answers0