喜欢原味奶茶 2016-07-25 11:38 采纳率: 33.3%
浏览 1168

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条回答 默认 最新

  • GrayHJX 2016-07-26 03:31
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)