An error is reported when running connection pool in idea: java.sql.sqlexception: Unsupported character encoding ‘UTF-8’
//run
public static void main(String[] args) throws SQLException {
ConPool pool = new ConPool("mysql");
pool.initPool(5);
PoolCon borrow = pool.borrow();
ResultSet resultSet = borrow.getCon().createStatement().executeQuery("select * from master_tab");
while (resultSet.next()) {
System.out.println(resultSet.getString("name"));
}
}
Error reporting interface:
java.sql.SQLException: Unsupported character encoding 'utf-8 '. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) at com.mysql.jdbc.ConnectionPropertiesImpl.postInitialization(ConnectionPropertiesImpl.java:2575) at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2545) at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3143) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at cn.kgc.base.ConPool.con(ConPool.java:82) at cn.kgc.base.ConPool.initPool(ConPool.java:96) at cn.kgc.base.ConPool.main(ConPool.java:149) java.sql.SQLException: Unsupported character encoding 'utf-8 '. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) at com.mysql.jdbc.ConnectionPropertiesImpl.postInitialization(ConnectionPropertiesImpl.java:2575) at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2545) at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3143) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at cn.kgc.base.ConPool.con(ConPool.java:82) at cn.kgc.base.ConPool.initPool(ConPool.java:96) at cn.kgc.base.ConPool.main(ConPool.java:149) java.sql.SQLException: Unsupported character encoding 'utf-8 '. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) at com.mysql.jdbc.ConnectionPropertiesImpl.postInitialization(ConnectionPropertiesImpl.java:2575) at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2545) at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3143) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at cn.kgc.base.ConPool.con(ConPool.java:82) at cn.kgc.base.ConPool.initPool(ConPool.java:96) at cn.kgc.base.ConPool.main(ConPool.java:149) java.sql.SQLException: Unsupported character encoding 'utf-8 '. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) at com.mysql.jdbc.ConnectionPropertiesImpl.postInitialization(ConnectionPropertiesImpl.java:2575) at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2545) at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3143) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at cn.kgc.base.ConPool.con(ConPool.java:82) at cn.kgc.base.ConPool.initPool(ConPool.java:96) at cn.kgc.base.ConPool.main(ConPool.java:149) java.sql.SQLException: Unsupported character encoding 'utf-8 '. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) at com.mysql.jdbc.ConnectionPropertiesImpl.postInitialization(ConnectionPropertiesImpl.java:2575) at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2545) at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3143) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at cn.kgc.base.ConPool.con(ConPool.java:82) at cn.kgc.base.ConPool.initPool(ConPool.java:96) at cn.kgc.base.ConPool.main(ConPool.java:149) Pool connection object initialization not yet halfway exception Process finished with exit code -4
Problems found in XML file: <value></value> The code is too long when writing, and the </value> Line breaks were made.
<configuration>
<datasource id="mysql">
<property>
<name>driver</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>url</name>
<value>jdbc:mysql://192.168.1.200:3306/master_slave_copy?useSSL=true&useUnicode=true&characterEncoding=utf-8
</value>//Error
</property>
<property>
<name>username</name>
<value>root</value>
</property>
<property>
<name>password</name>
<value>ok</value>
</property>
</datasource>
<datasource id="oracle"></datasource>
</configuration>
Solution: add </value> Adjust to <value> Same line
<configuration>
<datasource id="mysql">
<property>
<name>driver</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>url</name>
<value>jdbc:mysql://192.168.1.200:3306/master_slave_copy?useSSL=true&useUnicode=true&characterEncoding=utf-8</value>
</property>
<property>
<name>username</name>
<value>root</value>
</property>
<property>
<name>password</name>
<value>ok</value>
</property>
</datasource>
<datasource id="oracle"></datasource>
</configuration>
Run successfully!
Read More:
- [Solved] Error updating database. Cause: java.sql.SQLException: Unknown initial character set index ‘255‘ re
- [Solved] mybatis Error querying database. Cause: java.sql.SQLException: The server time zone value
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- [Solved] Error updating database. Cause: java.sql.SQLException: Incorrect integer value: ‘**‘ for column
- [Solved] java.sql.SQLException: Unknown system variable cache query size
- Java.sql.sqlexception: unable to read more data from socket
- Error querying database.Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource.
- [Solved] java.sql.SQLException: Table ‘xxx.hibernate_sequence’ doesn’t exist
- API Failed to Connect phoenix Error: java.sql.SQLException: ERROR 726 (43M10): Inconsistent namespace mapping properties
- [Solved] IDEA jdbc Connect Database Error: java.sql.SQLException: Undefined Error
- [Solved] JAVA Operate Database Error: You have an error in your SQL syntax; Dao layer SQL statement error
- [How to Fix]java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x98\x82\xF0\x9F…’
- [Solved] Linux java -jar Start Project Error: Unsupported major.minor version 52.0
- [How to Solve Error]java.util.Date cannot be cast to java.sql.Date
- JAVA Error: Error attempting to get column ‘XXX’ from result set. Cause java.sql.
- [Solved] Spring jdbctemplate Error: ‘Java. SQL. Driver’ for property ‘driver’: no
- Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is no
- [Solved] Error attempting to get column ‘xxxx_time‘ from result set. Cause: java.sql.SQLFeatureNotSupportedEx
- Java database Druid error: com.alibaba.druid.pool.DruidDataSource error
- [Solved] Maven Startup Error: Malformed \uxxxx encoding