When java connects to mysql database, insert Chinese display? problem solution

1. When configuring the parameters for connecting to the database in xml

Add the connection string encoding when connecting to the database after the jdbcUrl attribute

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
  <default-config>
    <property name="driverClass">com.mysql.jdbc.Driver</property>
    <property name="jdbcUrl">jdbc:mysql://localhost:3306/dms?useUnicode=true&characterEncoding=UTF-8</property>
    <property name="user">root</property>
    <property name="password">12345</property>
  </default-config>
</c3p0-config>


2. When configuring the parameters for connecting to the database in db.properties

Add the connection string encoding when connecting to the database after the jdbcUrl attribute


dataSource.driverClass=com.mysql.jdbc.Driver
dataSource.jdbcUrl=jdbc:mysql://127.0.0.1:3306/dms?useUnicode=true&characterEncoding=utf8
dataSource.user=root
dataSource.password=12345




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325786300&siteId=291194637