首页 > 代码库 > tomcat连接mysql的3个问题解决

tomcat连接mysql的3个问题解决

转载请标明出处:
本文出自:【ouyida3的博客】

1、BasicDataSourceFactory

Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory
解决:tomcat里原来oracle的factory忘了去掉了

<Resource name="jdbc/sdact1ds"
      auth="Container"
      type="javax.sql.DataSource"   
      factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
      driverClassName="oracle.jdbc.driver.OracleDriver"   
      url="jdbc:oracle:thin:@13.121.2.13:1521:bsstest"   
      username="ucr_ap"   
      password="ucr_ap"
      maxActive="60"
      maxIdle="20"
      maxWait="10000"
      removeAbandoned="true"
      removeAbandonedTimeout="60"
      logAbandoned="true"/>

2、No suitable driver

Caused by: java.sql.SQLException: No suitable driver
解决:和上面相似,还是tomcat里的Resource节点没有配置对

<Resource name="ds_zplat_cen1"
      auth="Container"
      type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://13.51.23.24:3010/zplatdb"   
      username="zplat_cen1"
      password="12345"
      maxActive="60"
      maxIdle="20"
      maxWait="10000"
      removeAbandoned="true"
      removeAbandonedTimeout="60"
      logAbandoned="true"
      defaultAutoCommit="false"/>

3、isValid(I)Z

Caused by: java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z
解决:mysql的jar版本号过低引起,改为mysql-connector-java-5.1.34.jar就可以(注意官网最新的是5.1.35,懒得下载最新了。这个5.1.34在tomcat8里跑没问题)
官网下载地址:http://dev.mysql.com/downloads/connector/j/

2015.6.30

<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

tomcat连接mysql的3个问题解决