spring_hibernate_sqlException_转

为struts+spring+hibernate增加显示数据库操作语句功能
①log4j以及Hibernate的:hibernate.show_sql=true作法只能输出一堆带“?”的语句,具体参数不见!!

② 用cownew的jdbmonitor,按照教程上所说将原来的数据库驱动直接改 为:com.cownew.JDBMonitor.jdbc.DBDriver,并在原数据库URL前增加:listenerconfig=c:/log /jdbmonitor/config.xml:的做法

  1. #      < bean   id = "datasource"
  2. #          class = "org.springframework.jdbc.datasource.DriverManagerDataSource" >
  3. #          < property   name = "driverClassName" >
  4. #              < value > com.cownew.JDBMonitor.jdbc.DBDriver </ value >
  5. #          </ property >
  6. #          < property   name = "url" >
  7. #              < value > listenerconfig =c:/log/jdbmonitor/config.xml:jdbc:mysql://localhost:3306/my_db </ value >
  8. #          </ property >
  9. #          < property   name = "username" >
  10. #              < value > myTest </ value >
  11. #          </ property >
  12. #          < property   name = "password" >
  13. #              < value > test </ value >
  14. #          </ property >
  15. #      </ bean >


会报错:
java.sql.SQLException: No suitable driver found for listenerconfig=c:/log/jdbmonitor/config.xml:jdbc:mysql://localhost:3306 /my_db。
错误原因不清楚,是否与org.springframework.jdbc.datasource.DriverManagerDataSource有关呢?

③按照网上所说配置p6spy:
* 将p6spy.jar放到WEB-INF/lib目录下,将spy.properties放到WEB-INF/classes目录下。
* 修改原有 JDBC Driver为:com.p6spy.engine.spy.P6SpyDriver
* 修改 spy.properties 中的 realdriver 值为原有的JDBC Driver,如:com.mysql.jdbc.Driver
也是报错:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/my_db。

④终于在:http://forum.springframework.org/archive/index.php/t-42994.html上发现了同样的问题,以无比激动的心情一路修改配置:

  1.      < bean   id = "datasource"
  2.          class = "org.springframework.jdbc.datasource.DriverManagerDataSource" >
  3.          < property   name = "driverClassName" >
  4.              < value > com.mysql.jdbc.Driver </ value >
  5.          </ property >
  6.          < property   name = "url" >
  7.              < value > jdbc:mysql://localhost:3306/my_db </ value >
  8.          </ property >
  9.          < property   name = "username" >
  10.              < value > myTest </ value >
  11.          </ property >
  12.          < property   name = "password" >
  13.              < value > test </ value >
  14.          </ property >
  15.      </ bean >
  16.      < bean   id = "myP6DataSource"   class = "com.p6spy.engine.spy.P6DataSource" >
  17.          < constructor-arg >
  18.              < ref   local = "datasource" />
  19.          </ constructor-arg >
  20.      </ bean >
  21.      < bean   id = "sessionFactory"
  22.          class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
  23.          < property   name = "dataSource" >
  24.              < ref   local = "myP6DataSource"   />
  25.          </ property >
  26.      </ bean >


但是却没有等到期望的结果,如此优雅的解决办法怎么会没有结果呢?
不断的调试终于发现了问题之所在:tomcat放在“Program Files”目录下,p6spy竟然不认识此目录! 发表于 @ 2008年

你可能感兴趣的:(spring,Hibernate,mysql,bean,jdbc)