我想以Windows身份验证模式将Java EE Web应用程序连接到SQL Server数据库。我有两个Spring.xml文件,即Spring-Datasource.xml和Spring-Customer.xml,它们都被导入到Spring-Module.xml中。这是我的Spring-Datasource.xml文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=Spring;" />
</bean>
</beans>
这是我的主班:
package com.mkyong.common;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.mkyong.customer.dao.CustomerDAO;
import com.mkyong.customer.model.Customer;
public class App {
public static void main(String[] args) {
try {
ApplicationContext context;
context = new ClassPathXmlApplicationContext("Spring-Module.xml");
CustomerDAO customerDAO = (CustomerDAO) context.getBean("customerDAO");
Customer customer;
customer = new Customer("mkyong", 28);
customerDAO.insert(customer);
Customer customer1 = customerDAO.findByCustomerId(1);
System.out.println(customer1);
} catch (Exception e) {
System.out.println("********************************************");
System.out.println(e.getMessage());
System.out.println("********************************************");
}
}
}
但是我总是得到这个错误:
******************************************** org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver' ********************************************
我该如何解决?
注意:我是Java的初学者
您的类路径中是否有JDBC驱动程序库?对于j2ee,它应该位于lib文件夹中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句