eclipse向MySQL workbench插入中文顯示亂碼
問題描述如下:我們在eclipse中向MySQL中插入數據
statement.executeUpdate("INSERT INTO word VALUES ('鮮花','2')");
然而我們發現
解決方法:我們爲mysql數據庫的連接字符串設置編碼方式
將原先的代碼
Connection c =DriverManager.getConnection("jdbc:mysql://localhost:3306/words","root","");
修改爲
Connection c
=DriverManager.getConnection("jdbc:mysql://localhost:3306/words?characterEncoding=utf8","root","");