Tomcat+MySQL应用服务器错误问题笔记

问题一:

错误信息:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

解决方法:

“com.mysql.jdbc.Driver”已被弃用。新的驱动程序类是`com.mysql.cj.jdbc.Driver'

问题二:

错误信息:

The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

翻译:服务器时区值'?? u±e×??±??未被识别或代表多个时区。如果希望利用时区支持,必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性),以使用更特殊的时区值。

解决方法:

在数据库Url后面添加“?serverTimezone=GMT”,重启服务器

问题三:

错误信息:

客服端HttpURLConnection以post传中文数据时,服务器request接收中文乱码

解决方法:

在客服端out.writeBytes(string);  改成 out.write(string.getBytes());

DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.write(request.getJsonStr().getBytes());
//out.writeBytes(request.getJsonStr());//中文乱码罪魁祸首
out.flush();

原因:

因为java里的char类型是16位的,一个char可以存储一个中文字符,在将其转换为 byte后高8位会丢失,这样就无法将中文字符完整的输出到输出流中。所以在可能有中文字符输出的地方最好先将其转换为字节数组,然后再通过write写入流,目前尝试过这种方法:把上面链接代码中的out.writeBytes(content);替换为out.write(content.getBytes());先把数据转成BYTE在写入流,执行成功,服务器接收正确的中文内容

解决方法来源:

洋杨阳--writeBytes()存在的问题

的阿尔额--HttpURLConnection以post传数据时中文乱码的一个解决方法
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值