baomidou / dynamic-datasource

dynamic datasource for springboot 多数据源 动态数据源 主从分离 读写分离 分布式事务
https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611
Apache License 2.0
4.74k stars 1.19k forks source link

oracle如何设置客户端、服务端字符集 #596

Closed wangzhaoqiang closed 11 months ago

wangzhaoqiang commented 11 months ago

Enviroment

JDK Version(required): 1.8

SpringBoot Version(required): 2.5.15

dynamic-datasource-spring-boot-starter Version(required):4.2.0

druid Version(optional):1.2.16

oracle version:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

oracle NLS_CHARACTERSET:US7ASCII

Describe what happened

Expected Result: 插入中文正常显示。

Actual Result: 插入中文为乱码。

这是我的配置文件

# 数据源配置
spring:
  datasource:
    druid:
      stat-view-servlet:
        enabled: true
        # 设置白名单,不填则允许所有访问
        allow:
        url-pattern: /druid/*
        # 控制台管理用户名和密码
        login-username: 9XvgGICy
        login-password: YlMbwtY6
      webStatFilter:
        enabled: true
    dynamic:
      #设置默认的数据源或者数据源组,默认值即为master
      primary: master
      #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
      strict: false
      druid:
        # 初始连接数
        initialSize: 5
        # 最小连接池数量
        minIdle: 5
        # 最大连接池数量
        maxActive: 20
        # 配置获取连接等待超时的时间
        maxWait: 60000
        # 配置连接超时时间
        connectTimeout: 30000
        # 配置网络超时时间
        socketTimeout: 60000
        # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
        timeBetweenEvictionRunsMillis: 60000
        # 配置一个连接在池中最小生存的时间,单位是毫秒
        minEvictableIdleTimeMillis: 300000
        # 配置一个连接在池中最大生存的时间,单位是毫秒
        maxEvictableIdleTimeMillis: 900000
        # 配置检测连接是否有效
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxPoolPreparedStatementPerConnectionSize: 20
        filters: stat,wall,slf4j
        wall:
          multiStatementAllow: true
        stat:
          merge-sql: true
          log-slow-sql: true
          slow-sql-millis: 2000
      datasource:
        master:
          url: jdbc:mysql://localhost:3306/ry-vue-spd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true
          username: root
          password: 123456
          driver-class-name: com.mysql.cj.jdbc.Driver
          druid:
            validation-query: SELECT 1 FROM DUAL
        oracle:
          url: jdbc:wrap-jdbc:filters=encoding:jdbc:oracle:thin:@127.0.0.1:1521:orcl
          username: scott
          password: tiger
          driver-class-name: oracle.jdbc.OracleDriver
          druid:
            validation-query: SELECT 1 FROM DUAL
            connection-properties: clientEncoding=GBK;serverEncoding=ISO-8859-1
        sqlserver:
          url: jdbc:sqlserver://127.0.0.1:1433;SelectMethod=cursor;DatabaseName=ry-vue-spd
          username: sa
          password: 123456
          driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
          druid:
            validation-query: SELECT 1
huayanYu commented 11 months ago

连接池或者数据库的事情.

jie911 commented 7 months ago
        oracle:
          url: jdbc:wrap-jdbc:filters=encoding:jdbc:oracle:thin:@127.0.0.1:1521:orcl
          username: scott
          password: tiger
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: oracle.jdbc.OracleDriver
          druid:
            validation-query: SELECT 1 FROM DUAL
            connection-properties: 
              clientEncoding: GBK
              serverEncoding: ISO-8859-1

这么写,希望能帮到你