无法在spring中加载JDBC驱动程序类

时间:2016-08-04 09:44:59

标签: spring jdbc

我使用spring框架从数据库访问数据。当我运行主类时,我收到一条错误import xxx def fun1() def fun2() ... def main(): task = sys.argv[1] if task =='task1': do task1 elif task == 'task2': do task2 ... if __name__ == '__main__': main() 。我添加了sqljdbc4-2 jar文件。 App.java是我的主要类。我还附加了我的Spring XML文件。请求帮助我们解决这个问题

if

弹簧Datasource.xml

java.lang.IllegalStateException: Could not load JDBC driver class [com.microsoft.sqlserver.jdbc.SQLServerD??river]

弹簧Module.xml

package org.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App 
{
  public static void main( String[] args )
 {
    ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
     System.out.println("inside test");
    CustomerDAO customerDAO = (CustomerDAO) context.getBean("customerDAO");
    Customer customer = new Customer(1, "mkyong",28);
    customerDAO.insert(customer);

    Customer customer1 = customerDAO.findByCustomerId(1);
    System.out.println(customer1);

 }
}

弹簧Customer.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.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerD‌​river"/>
    <property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=JAVADB"/>
    <property name="username" value="sa"/>
    <property name="password" value="dbadmin@234"/>
</bean>
</beans>

0 个答案:

没有答案