zoukankan      html  css  js  c++  java
  • tomcat数据源配置

    MySQL数据库在使用汉字进行查询的时候容易出错,如查询:

    select * from e_document where E_WENHAO   like '山大%'

    明明在数据库中有相关数据,但是却查询不出结果。这时候需要在建立连接的时候,将连接改为如下形式:

    DriverManager.getConnection("jdbc:mysql://localhost/edoas2?user=root&password=&useUnicode=true&characterEncoding=GB2312")

    问题解决。但是在tomcat中使用datasource数据源来配置连接,这时候如果将连接数据源中的:

    url="jdbc:mysql://192.168.1.6/123paibbs?useUnicode=true&characterEncoding=GBK"
    由于tomcat得xml文件解析问题,tomcat启动会产生错误:

    Parse Fatal Error at line 373 column 80: The reference to entity "characterEncoding" must end with the ';' delimiter.

    这时候需要将url改为如下形式:

    url="jdbc:mysql://127.0.0.1:3306/edoas2?useUnicode=true&characterEncoding=GB2312"

    最后Server.xml配置如下:

    <Resource
          name="java/mysql"
          type="javax.sql.DataSource"    
          driverClassName="com.mysql.jdbc.Driver"
          maxIdle="2"
          maxWait="5000"     
          username="root"
          url="jdbc:mysql://127.0.0.1:3306/edoas2?useUnicode=true&amp;characterEncoding=GB2312"
          password=""
          maxActive="20"/>

    web.xml配置如:

       <resource-ref>
        <description>MySQL DB Connection Pool</description>
        <res-ref-name>java/mysql</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>

    context.xml配置为:

    <ResourceLink
       name="java/mysql"
       type="javax.sql.DataSource"
       global="java/mysql"/>

  • 相关阅读:
    JDK6的switch支持不是很好
    团队作业(2)
    团队作业(1)
    4月30日
    重构:改善既有代码的设计有感
    4月28日
    4月27日
    4月26日
    4月25日
    4月24日
  • 原文地址:https://www.cnblogs.com/macula7/p/1960470.html
Copyright © 2011-2022 走看看