在IDEA中运行连接池出现报错:java.sql.SQLException: Unsupported character encoding 'utf-8'.
//测试运行代码 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")); } }
报错界面:
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.(ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection. (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. (ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection. (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. (ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection. (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. (ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection. (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. (ConnectionImpl.java:762) at com.mysql.jdbc.JDBC4Connection. (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) 池连接对象初始化未过半异常 Process finished with exit code -4
driver com.mysql.jdbc.Driver url jdbc:mysql://192.168.1.200:3306/master_slave_copy?useSSL=true&useUnicode=true&characterEncoding=utf-8 //问题出处username root password ok
解决方案:将调整至与
driver com.mysql.jdbc.Driver url jdbc:mysql://192.168.1.200:3306/master_slave_copy?useSSL=true&useUnicode=true&characterEncoding=utf-8 username root password ok
运行成功!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)