Spring访问数据库问题

Dao的内容
public class StudentDao extends JdbcDaoSupport{

public void insertStudent(Student student) {
    String sql = "insert into test(name) values(?)";
    this.getJdbcTemplate().update(sql,student.getName());
}

}

业务代码
public class StudentImp implements IStudentImp{
private StudentDao dao;

public void setDao(StudentDao dao) {
    this.dao = dao;
}
public void add(Student student){
    dao.insertStudent(student);
}

}

配置文件:

<bean id="myDatasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/studentdao"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>
</bean>
    <!--注册Dao  -->
<bean id="mydao" class="com.spring.dao.StudentDao">
    <property name="dataSource" ref="myDatasource"></property>
</bean>
<!-- 注册service -->
<bean id="myservice" class="com.spring.service.StudentImp">
    <property name="dao" ref="mydao"/>
</bean>

测试代码:
    public void testadd(){
    ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
    IStudentImp studentimp = (IStudentImp)ac.getBean("myservice");
    Student student = new Student("jacke");
    studentimp.add(student);
}

报错:

图片说明
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.jdbc.core.StatementCreatorUtils
at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.cleanupParameters(ArgumentPreparedStatementSetter.java:72)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:924)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:909)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980)
at com.spring.dao.StudentDao.insertStudent(StudentDao.java:12)
at com.spring.service.StudentImp.add(StudentImp.java:13)
at com.spring.test.Test.testadd(Test.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

到底哪里出问题了啊!

在跟断点的时候,里面有一个异常:
EXCEPTION: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed.
但到底是如何能解决实在没法,求大神帮忙

1个回答

程序和数据库断掉了。。。你重启一下tomcat和mysql看看

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!