title: Unable to connect to SQL Server via JDBC. No suitable driver found for jdbc:sqlserver://
body: <p>I simply want to use SQL Server database in my HTTP Servlet program but my program can't seem to connect to the database. It gives me the following error:</p>
  
  <blockquote>
    <p>No suitable driver found for
    jdbc:sqlserver://localhost:1433;databaseName=Bookyard;integratedSecurity=true;</p>
  </blockquote>
  
  <p>This is my connection method.</p>
  
  <pre><code>package practice.bookyard.server.util;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  
  public class Database {
  
      public static Connection getConnection() {
          String url = "jdbc:sqlserver://(LocalDb)\\MSSQLLocalDB:1433;databaseName=Bookyard;integratedSecurity=true;";
          Connection connection = null;
  
          try {
              connection = DriverManager.getConnection(url);
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
          return connection;
      }
  
  }
  </code></pre>
  
  <p>I had the sever name as <code>localhost:1433</code> earlier but I changed it to the SQL Server instance name <code>(LocalDb)\\MSSQLLocalDB:1433</code> but it still seems to pick up the old name.</p>
  
  <p>Also, I am not sure how to provide the right connection string when connecting to SQL Server localdb.</p>
  
  <p>I am using Eclipse for Java EE, Mars 2, and I downloaded Microsoft JDBC drivers for SQL 6.0 from <a href="https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&amp;id=11774" rel="nofollow noreferrer">this website</a>.</p>
  
  <p>I ran the installation, unzipped the contents of the resulting folder. Then, I added the <strong>sqljdbc42.jar</strong> file to the build path as I am targeting JDK 1.8.</p>
  
  <p><a href="https://i.stack.imgur.com/r54gM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r54gM.png" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Upon Scary Wombat's suggestion, I have also added the path to the <strong>sqljdbc42.jar</strong> file to my classpath.</p>
  
  <p><a href="https://i.stack.imgur.com/k4Km3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k4Km3.png" alt="enter image description here"></a></p>
  
  <p>However, I still get the same error.</p>
  
  <p>I am pretty confident this is a reflection issue, in that the type loader isn't able to resolve the driver type from my connection string. Which means, the connection string syntax I am using is wrong.</p>
  
  <p>I changed my connection string to read as follows:</p>
  
  <pre><code>String url = "jdbc:sqlserver://localhost:1433;
  instance=(LocalDb)\\MSSQLLocalDB;
  databaseName=Bookyard;integratedSecurity=true;";
  </code></pre>
  
  <p>However, I still not only get the same error but the exception message I receive still has my <em>old connection string</em>. So, clearly, there's also some caching going on, I just don't know where. Who is caching my connection string and how do I refresh / clear that cache?</p>
  
  <p>Could you please tell me how to provide a SQL Server instance name if I am connecting to <strong>localdb</strong> and not on the main SQL Server instance?</p>