I am new to both the Java world and the Spring world, so there is a lot to learn. I am working on getting the Spring Framework JDBC working. I am finally to the point where the application is not able to find Microsoft's JDBC Driver. I am 99.9% sure the reason is that I don't have it referenced correctly within STS. Ideally I would prefer NOT to have to copy the jar file, but at this point, I am willing to do anything it takes to get it to work.
This Spring Application Context File seems to load correctly. In the same project, I was able to use Class.forName("com.microsoft.sqlserver.jdbc.Driver ") to set and load the jdbc driver with the old fashion JDBC framework. At the current time, I am simply including the Microsoft JDBC jar (sqljdbc4.jar) as a lib in the .classpath file:
Here is the app-context.xml file:Code:<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/> <classpathentry kind="lib" path="C:/Program Files/Microsoft JDBC Driver 4.0 for SQL Server/sqljdbc_4.0/enu/sqljdbc4.jar"/> <classpathentry kind="output" path="target/classes"/> </classpath>
SamCode:<?xml version="1.0" encoding="UTF-8"?> <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"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.Driver"/> <property name="url" value="jdbc:sqlserver://localhost;databaseName=ProSpringCh8"/> <property name="username" value="****"/> <property name="password" value="****"/> </bean> <context:property-placeholder location="jdbc.properties" /> <bean id="contactDao" class="com.accumed.DatabaseTest.dao.jdbc.xml.JdbcContactDao"> <property name="dataSource"> <ref local="dataSource"/> </property> </bean> </beans>


Reply With Quote