1
這裏是如何創建一個連接:Unicode字符保存爲使用JDBC,但可以正確保存使用phpMyAdmin
Class.forName("com.mysql.jdbc.Driver");
Properties properties = new Properties();
properties.setProperty("user", "root");
properties.setProperty("password", "PASSWORD");
properties.setProperty("useSSL", "false");
properties.setProperty("autoReconnect", "true");
properties.setProperty("useUnicode", "true");
properties.setProperty("characterEncoding", "UTF-8");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/coolpoop", properties);
PreparedStatement statement = connection.prepareStatement("SET NAMES 'utf8'");
statement.execute();
statement = connection.prepareStatement("SET CHARACTER SET utf8");
statement.execute();
表:
插入:
PreparedStatement state = Mysql.conn().prepareStatement("insert into contents(campaignId, site_id, original_article_id, title, content) values(-1, -1, -1, ?, ?)");
state.setString(1, "acbdąčęėįšųū");
state.setString(2, "acbdąčęėįšųū");
state.execute();
結果:
出了什麼問題?
什麼是您的數據庫編碼?你可以通過db客戶端插入UTF-8符號嗎? – borowis
@BorysZibrov查看EDIT1。沒有檢查數據庫編碼,但我懷疑它應該沒問題,如果我可以插入通過phpMyAdmin –
是的,那麼數據庫是好的,謝謝 – borowis