title: Installing MS SQL driver into Eclipse Maven
body: <p>How do I install MSSQL driver in my project with Eclipse's maven? (m2e)? And also make it not conflict with Vaadin? When I install the MSSQL driver locally <a href="https://stackoverflow.com/a/32760177/4691343">following these instructions</a>, during the compile and runtime, it says "Could not find archetype from Vaadin-addons."</p>
  
  <p>I have the code:</p>
  
  <pre><code>                Connection con = null;
                  Statement stmt = null;
                  ResultSet rs = null;
                  try {
                       Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
                      con = DriverManager.getConnection("jdbc:sqlserver://server;databaseName=dbname;user=username;password=password");
                      String sql = "Select * from Table1";
                      stmt = con.createStatement( );
                      rs = stmt.executeQuery(sql);
  
                      while (rs.next()){
                          contractorsList.addBean(new Contractor(rs.getString(1), 
                                  rs.getString(2), 
                                  rs.getString(3), 
                                  rs.getString(4), 
                                  rs.getString(5), 
                                  rs.getString(6))); 
                      }
  
                  } catch (SQLException | ClassNotFoundException e) {
                      e.printStackTrace();
                  }finally{
                      try { con.close();  } catch (SQLException e) {}
                      try { rs.close();   } catch (SQLException e) {}
                      try { stmt.close(); } catch (SQLException e) {}
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
      at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
      at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:450)
      at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403)
      at java.lang.Class.forName0(Native Method)
  </code></pre>
  
  <p>Which means that it can't find my driver, I think. So I'm following <a href="http://techmajik.com/2014/04/24/how-to-setup-maven-dependency-for-microsoft-sql-server/" rel="nofollow noreferrer">this tutorial</a> on installing the MS SQL driver. <a href="https://www.microsoft.com/en-us/download/details.aspx?id=11774" rel="nofollow noreferrer">I download the driver from microsoft</a> and then I unzip it here:</p>
  
  <pre><code>C:\SQLDriver
  </code></pre>
  
  <p>In Eclipse, on my project folder, I right click > Debug As > Debug Configurations > </p>
  
  <pre><code>mvn install:install-file -Dfile=C:\SQLDriver\sqljdbc_4.0\enu\sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0.2206.100 -Dpackaging=jar
  </code></pre>
  
  <p>Then I add in the following in my POM</p>
  
  <pre><code>&lt;properties&gt;
  &lt;!–….other versions–&gt;
  &lt;sqlserver.version&gt;4.0.2206.100&lt;/sqlserver.version&gt;
  &lt;/properties&gt;
  ...
  &lt;dependency&gt;
  &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
  &lt;artifactId&gt;sqljdbc4&lt;/artifactId&gt;
  &lt;version&gt;${sqlserver.version}&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I get an error that it can't find my dependency, So I look up the question here, and I found out that I simply need to add sqljdbc4 to my classpath.</p>
  
  <p>I have no idea what that means but <a href="https://blogs.msdn.microsoft.com/brian_swan/2011/03/02/getting-started-with-the-sql-server-jdbc-driver/" rel="nofollow noreferrer">google took me here</a> So I attempt to follow the instructions.</p>
  
  <p>In System Properties > Advanced > Environment Variable under Variables, I add the following:</p>
  
  <p><a href="https://i.stack.imgur.com/72hjN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/72hjN.jpg" alt="enter image description here"></a></p>
  
  <p>I searched here and it looks like someone else asked the <a href="https://stackoverflow.com/questions/18200823/installing-and-using-ms-sql-jdbc-driver">same question</a></p>
  
  <p>I honestly don't know what people mean by add it to the classpath. Do they mean paste the jars in the same folder as the project? Either way, I just found a .classpath file in my project and added these:</p>
  
  <p><a href="https://i.stack.imgur.com/mdhlo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mdhlo.jpg" alt="enter image description here"></a></p>
  
  <p>How do I get maven to use this microsoft sql driver?</p>
  
  <p><strong>[Edit]</strong> When going to Libraries > Maven Dependencies, right click > build path > configure build path, I see this:</p>
  
  <p><a href="https://i.stack.imgur.com/wbV5T.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wbV5T.jpg" alt="enter image description here"></a></p>
  
  <p>Which, when I click, it doesn't let me edit the path of that file. I'm not sure where to edit it.</p>