title: JavaEE/Tomcat 9.0.0/ IntellijIdea 2016.2: java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
body: <p>There is a problem with connectors in my project. I have added MySQL connector to Tomcat's lib and also to project's path in IntellijIDEA but problem still exist. Answers from older versions in stackoverlow didnt work in here.
   Here are project classes:</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1"&gt;
  
      &lt;resource-ref&gt;
          &lt;description&gt;DB Connection&lt;/description&gt;
          &lt;res-ref-name&gt;jdbc/library&lt;/res-ref-name&gt;
          &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;/resource-ref&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context path="/myApp" docBase="myApp"
           crossContext="true" reloadable="true" debug="1"&gt;
      &lt;Resource name="jdbc/library"
                global="jbc/library"
                auth="Container"
                type="javax.sql.DataSource"
                initialSize="10"
                maxTotal="100"
                maxIdle="30"
                maxWaitMillis="10000"
                username="root"
                password="admin"
                driverClassName="com.mysql.jdbc.Driver"
                url="jdbc:mysql://localhost:3306/library" /&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>error.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
           pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;Upss&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Something is wrong&lt;/h1&gt;
  &lt;a href="index.jsp"&gt;Try again&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>index.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
           pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
    &lt;title&gt;Library Viewer&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Biblioteka viewer&lt;/h1&gt;
  &lt;form action="BookServlet" method="post"&gt;
    &lt;input placeHolder="ISBN" type="text" name="isbn"&gt;
    &lt;br&gt;
    &lt;input placeHolder="Tytuł" type="text" name="title"&gt;
    &lt;br&gt;
    &lt;input placeHolder="Opis" type="text" name="description"&gt;
    &lt;br&gt;
    Szukaj: &lt;input type="radio" name="option" value="search"&gt; Dodaj: &lt;input type="radio" name="option" value="add"&gt;
    Modyfikuj: &lt;input type="radio" name="option" value="update"&gt; Usuń: &lt;input type="radio" name="option" value="delete"&gt;
    &lt;br&gt;
    &lt;input type="submit" value="Wyślij"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>result.jsp</p>
  
  <pre><code>&lt;%@page import="pl.javastart.model.Book"%&gt;
  &lt;%@ page language="java" contentType="text/html; charset=UTF-8"
           pageEncoding="UTF-8"%&gt;
  &lt;% Book book = (Book)request.getAttribute("book"); %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Wynik zapytania &lt;%= request.getAttribute("option") %&gt;&lt;/h1&gt;
  &lt;p&gt;W wyniku Twojego zapytania otrzymano następujacy wynik:&lt;/p&gt;
  &lt;p&gt;Title: &lt;%= book.getTitle() %&gt;&lt;br&gt;
      ISBN: &lt;%= book.getIsbn() %&gt;&lt;br&gt;
      Descrition: &lt;%= book.getDescription() %&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Book.java</p>
  
  <pre><code>package pl.javastart.model;
  
  public class Book {
      private String isbn;
      private String title;
      private String description;
      public String getIsbn() {
          return isbn;
      }
      public void setIsbn(String isbn) {
          this.isbn = isbn;
      }
      public String getTitle() {
          return title;
      }
      public void setTitle(String title) {
          this.title = title;
      }
      public String getDescription() {
          return description;
      }
      public void setDescription(String description) {
          this.description = description;
      }
  
      public Book(){}
      public Book(String isbn, String title, String desc){
          this.isbn = isbn;
          this.title = title;
          description = desc;
      }
  }
  </code></pre>
  
  <p>BookServlet.java</p>
  
  <pre><code>package pl.javastart.servlet;
  
  import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import pl.javastart.dao.BookDAO;
  import pl.javastart.model.Book;
  
  @WebServlet("/BookServlet")
  public class BookServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      protected void doGet(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
          doPost(request, response);
      }
  
      protected void doPost(HttpServletRequest request,
                            HttpServletResponse response) throws ServletException, IOException {
          request.setCharacterEncoding("UTF-8");
          String isbn = request.getParameter("isbn");
          String title = request.getParameter("title");
          String description = request.getParameter("description");
          String option = request.getParameter("option");
          BookDAO dao = new BookDAO();
          Book book = null;
          String operation = null;
          boolean result = false;
          if("search".equals(option)) {
              book = dao.read(isbn);
              result = book!=null? true:false;
              operation = "search";
          } else if("add".equals(option)) {
              book = new Book(isbn, title, description);
              result = dao.create(book);
              operation = "add";
          } else if("update".equals(option)) {
              book = new Book(isbn, title, description);
              result = dao.update(book);
              operation = "update";
          } else if("delete".equals(option)) {
              book = new Book(isbn, title, description);
              result = dao.delete(book);
              operation = "delete";
          }
          if(book != null &amp;&amp; result) {
              request.setAttribute("option", operation);
              request.setAttribute("book", book);
              request.getRequestDispatcher("result.jsp").forward(request, response);
          } else {
              request.getRequestDispatcher("error.jsp").forward(request, response);
          }
      }
  
  }
  </code></pre>
  
  <p>BookDAO.java</p>
  
  <pre><code>package pl.javastart.dao;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  import pl.javastart.model.Book;
  import pl.javastart.util.ConnectionProvider;
  
  public class BookDAO {
  
      private final static String CREATE = "INSERT INTO book(isbn, title, description) VALUES(?, ?, ?);";
      private final static String READ = "SELECT isbn, title, description FROM book WHERE isbn = ?;";
      private final static String UPDATE = "UPDATE book SET isbn=?, title=?, description=? WHERE isbn = ?;";
      private final static String DELETE = "DELETE FROM book WHERE isbn=?;";
  
      public boolean create(Book book) {
          Connection conn = null;
          PreparedStatement prepStmt = null;
          boolean result = false;
          try {
              conn = ConnectionProvider.getConnection();
              prepStmt = conn.prepareStatement(CREATE);
              prepStmt.setString(1, book.getIsbn());
              prepStmt.setString(2, book.getTitle());
              prepStmt.setString(3, book.getDescription());
              int rowsAffected = prepStmt.executeUpdate();
              if (rowsAffected &gt; 0) {
                  result = true;
              }
          } catch (SQLException e) {
              e.printStackTrace();
          } finally {
              releaseResources(prepStmt, null, conn);
          }
          return result;
      }
  
      public Book read(String isbn) {
          Connection conn = null;
          PreparedStatement prepStmt = null;
          ResultSet resultSet = null;
          Book resultBook = null;
          try {
              conn = ConnectionProvider.getConnection();
              prepStmt = conn.prepareStatement(READ);
              prepStmt.setString(1, isbn);
              resultSet = prepStmt.executeQuery();
              if(resultSet.next()) {
                  resultBook = new Book();
                  resultBook.setIsbn(resultSet.getString("isbn"));
                  resultBook.setTitle(resultSet.getString("title"));
                  resultBook.setDescription(resultSet.getString("description"));
              }
          } catch (SQLException e) {
              e.printStackTrace();
          } finally {
              releaseResources(prepStmt, resultSet, conn);
          }
          return resultBook;
      }
  
      public boolean update(Book book) {
          Connection conn = null;
          PreparedStatement prepStmt = null;
          boolean result = false;
          try {
              conn = ConnectionProvider.getConnection();
              prepStmt = conn.prepareStatement(UPDATE);
              prepStmt.setString(1, book.getIsbn());
              prepStmt.setString(2, book.getTitle());
              prepStmt.setString(3, book.getDescription());
              prepStmt.setString(4, book.getIsbn());
              int rowsAffected = prepStmt.executeUpdate();
              if (rowsAffected &gt; 0) {
                  result = true;
              }
          } catch (SQLException e) {
              e.printStackTrace();
          } finally {
              releaseResources(prepStmt, null, conn);
          }
          return result;
      }
  
      public boolean delete(Book book) {
          Connection conn = null;
          PreparedStatement prepStmt = null;
          boolean result = false;
          try {
              conn = ConnectionProvider.getConnection();
              prepStmt = conn.prepareStatement(DELETE);
              prepStmt.setString(1, book.getIsbn());
              int rowsAffected = prepStmt.executeUpdate();
              if (rowsAffected &gt; 0) {
                  result = true;
              }
          } catch (SQLException e) {
              e.printStackTrace();
          } finally {
              releaseResources(prepStmt, null, conn);
          }
          return result;
      }
  
      private void releaseResources(PreparedStatement prepStmt, ResultSet res,
                                    Connection conn) {
          try {
              if (prepStmt != null &amp;&amp; !prepStmt.isClosed()) {
                  prepStmt.close();
              }
              if (res != null &amp;&amp; !res.isClosed()) {
                  res.close();
              }
              if (conn != null &amp;&amp; !conn.isClosed()) {
                  conn.close();
              }
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>ConnectionProvider.java</p>
  
  <pre><code>package pl.javastart.util;
  
  import java.sql.Connection;
  import java.sql.SQLException;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.sql.DataSource;
  
  public class ConnectionProvider {
      private static DataSource dataSource;
  
      public static Connection getConnection() throws SQLException {
          return getDSInstance().getConnection();
      }
  
      private static DataSource getDSInstance() {
          if(dataSource == null) {
              try {
                  Context initContext = new InitialContext();
                  Context envContext = (Context) initContext.lookup("java:comp/env");
                  dataSource = (DataSource) envContext.lookup("jdbc/library");
              } catch (NamingException e) {
                  e.printStackTrace();
              }
          }
          return dataSource;
      }
  }
  </code></pre>
  
  <p>Dao.iml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;module type="JAVA_MODULE" version="4"&gt;
    &lt;component name="FacetManager"&gt;
      &lt;facet type="web" name="Web"&gt;
        &lt;configuration&gt;
          &lt;descriptors&gt;
            &lt;deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" /&gt;
          &lt;/descriptors&gt;
          &lt;webroots&gt;
            &lt;root url="file://$MODULE_DIR$/web" relative="/" /&gt;
          &lt;/webroots&gt;
        &lt;/configuration&gt;
      &lt;/facet&gt;
    &lt;/component&gt;
    &lt;component name="NewModuleRootManager" inherit-compiler-output="true"&gt;
      &lt;exclude-output /&gt;
      &lt;content url="file://$MODULE_DIR$"&gt;
        &lt;sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /&gt;
      &lt;/content&gt;
      &lt;orderEntry type="inheritedJdk" /&gt;
      &lt;orderEntry type="sourceFolder" forTests="false" /&gt;
      &lt;orderEntry type="library" scope="PROVIDED" name="Tomcat 9.0.0.M9" level="application_server_libraries" /&gt;
      &lt;orderEntry type="library" name="mysql-connector-java-5.1.39-bin" level="project" /&gt;
    &lt;/component&gt;
  &lt;/module&gt;
  </code></pre>
  
  <p>Here is a screen with project structure:<a href="https://i.stack.imgur.com/Q8VV5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q8VV5.png" alt="enter image description here"></a></p>
  
  <p>And console: <a href="https://i.stack.imgur.com/7zgw3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7zgw3.png" alt="enter image description here"></a></p>