在mysql安裝目錄下的my.ini配置文件裏面加上一條 default-character-set=gbk
然後重啓mysql服務,注意 gbk 要小寫,不然 mysql 啓動不了。
然後把getConnection的url改成
jdbc:mysql://localhost:3306/sunshine?autoReconnect=true&useUnicode=true&characterEncoding=GBK
或者
jdbc:mysql://localhost:3306/sunshine?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8