title: java.sql.SQLException: No suitable driver
body: <p>I have create one <strong>maven</strong> project.</p>
  
  <p>I am try to connect MSSQL (Microsoft SQL Server 2014) with my J2EE application.
  But it throws following exception</p>
  
  <pre><code>org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
          at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
          at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
          at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
          at com.jagir.ecommerce.database.DatabaseConnection.testConnection(DatabaseConnection.java:27)
          at com.jagir.ecommerce.user.servlet.Registration.doGet(Registration.java:34)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
          at java.lang.Thread.run(Thread.java:745)
  Caused by: java.sql.SQLException: No suitable driver
          at java.sql.DriverManager.getDriver(DriverManager.java:315)
          at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(B
  asicDataSource.java:1437)
          ... 18 more
  </code></pre>
  
  <p>My code :</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
           http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
      version="3.1"&gt;
  
      &lt;display-name&gt;ecommerce&lt;/display-name&gt;
      &lt;resource-ref&gt;
          &lt;description&gt;Database connection&lt;/description&gt;
          &lt;res-ref-name&gt;jdbc/testdb&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;servlet&gt;
          &lt;servlet-name&gt;Registration&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.test.user.servlet.Registration&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Registration&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/registration&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Registration</p>
  
  <pre><code>public class Registration extends HttpServlet
  {
      private static final long serialVersionUID = 1L;
  
      public Registration()
      {
          super();
      }
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {       
          response.getWriter().append("Served at: ").append(request.getContextPath());
          request.setAttribute("title", "User Registration");
          new DatabaseConnection().testConnection();
          request.getRequestDispatcher("pages/user/registration.jsp").forward(request, response);
      }
  }
  </code></pre>
  
  <p>DatabaseConnection</p>
  
  <pre><code>public class DatabaseConnection
  {
      private DataSource dataSource;
      private Connection connection;
      private Statement statement;
  
      public void testConnection()
      {
          //get data source
          try
          {
              Context initContext = new InitialContext();
              Context envContext = (Context) initContext.lookup("java:/comp/env");
              dataSource  = (DataSource) envContext.lookup("jdbc/testdb");
              connection = dataSource.getConnection();
              statement = connection.createStatement();
              System.out.println("TEST");
              ResultSet rs = statement.executeQuery("select * from temp");
              System.out.println("Done");
              while(rs.next())
              {
                  System.out.println(rs.getString(0));
              }
          }
          catch (NamingException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          catch (SQLException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context path="/test" docBase="test" crossContext="true"
      reloadable="true" debug="1"&gt;
      &lt;!-- Specify a JDBC datasource --&gt;
  
      &lt;Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
          username="sa" password="password" driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
          url="jdbc:sqlserver://devmangal;databaseName=testV1.0;integratedSecurity=true"
          maxActive="10" maxIdle="4" /&gt;
  &lt;/Context&gt;
  </code></pre>