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"/>

  • 相关阅读:
    让man 显示中文
    对‘pthread_create’未定义的引用
    gcc和arm-linux-gcc区别
    ubuntu14.04下arm-linux-gcc 4.5.1的安装与配置
    MakeCode 递归生成资源文件
    Swagger 增加 DocumentFilter 隐藏不需要显示的接口
    Razor 模板自己渲染出结果 string
    .net core API 统一拦截错误
    内网机(无网络安装 .NET Core win开发环境
    netcore web.config ConnectionStrings AppSettings
  • 原文地址:https://www.cnblogs.com/macula7/p/1960470.html
Copyright © 2011-2022 走看看