title: Adding JDBC jar so Spring Framework can find it
body: <p>I am new to Java, Spring, and Eclipse.  I am working on a simple Spring program that is using Spring Framework JDBC to connect to Microsoft SQL Server 2012.  With the correct configuration I have succeeded in using the traditional JDBC to talk to the database.  The problem I am running into is the application is not able to find the Microsoft JDBC driver.  I am assuming it is simply a matter of referencing the JAR file differently.  Here is what I currently have for my classpath file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
      &lt;classpathentry kind="src" output="target/classes" path="src/main/java"/&gt;
      &lt;classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/&gt;
      &lt;classpathentry kind="lib" path="C:/Program Files/Microsoft JDBC Driver 4.0 for SQL Server/sqljdbc_4.0/enu/sqljdbc4.jar"/&gt;
      &lt;classpathentry kind="output" path="target/classes"/&gt;
  &lt;/classpath&gt;
  </code></pre>
  
  <p>And here is the app-context.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
        http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="com.microsoft.sqlserver.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:sqlserver://localhost;databaseName=ProSpringCh8"/&gt;
          &lt;property name="username" value="****"/&gt;
          &lt;property name="password" value="****"/&gt;
      &lt;/bean&gt;
  
      &lt;context:property-placeholder location="jdbc.properties" /&gt;
  
      &lt;bean id="contactDao" class="com.accumed.DatabaseTest.dao.jdbc.xml.JdbcContactDao"&gt;
          &lt;property name="dataSource"&gt;
              &lt;ref local="dataSource"/&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <hr>
  
  <p>I am running it from within Eclipse's debugger.  The errors I am getting are:</p>
  
  <pre><code>09:28:19,711 DEBUG g.springframework.jdbc.core.JdbcTemplate: 635 - Executing prepared SQL query
  09:28:19,726 DEBUG g.springframework.jdbc.core.JdbcTemplate: 570 - Executing prepared SQL statement [select first_name from contact where id = ?]
  09:28:19,774 DEBUG ramework.jdbc.datasource.DataSourceUtils: 110 - Fetching JDBC Connection from DataSource
  Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.Driver'
      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
      at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:729)
      at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:745)
      at com.accumed.DatabaseTest.dao.jdbc.xml.JdbcContactDao.findFirstNameById(JdbcContactDao.java:55)
      at com.accumed.DatabaseTest.JdbcContactDaoSample.main(JdbcContactDaoSample.java:21)
  Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.Driver'
      at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
      ... 8 more
  Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.Driver
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
      ... 12 more
  </code></pre>