字符编码报错

字符编码报错

http://img1.sycdn.imooc.com//climg/5d0d860e000144c913991104.jpg


java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)

at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1689)

at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3444)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2062)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)

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:408)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at com.imooc.jdbc.demo1.JDBCDemo1.main(JDBCDemo1.java:23)


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,

jdbc:mysql://localhost:3306/jdbctest

改为:

jdbc:mysql://localhost:3306/jdbctest?useUnicode=true&characterEncoding=utf8

再进行测试。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • 何时才能成大佬 提问者 #1
    谢谢老师 问题已解决 但是请问为啥会产生这样的报错啊?
    2019-06-22 10:13:07
提问者 何时才能成大佬 2019-06-22 09:38:54

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctest","root","123");


这一句报错

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师