Tag: utf 8

JDBC MySQL UTF-8字符串写入问题

连接到db: public DBSource(ConnectionInfo ci) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { Class.forName(“com.mysql.jdbc.Driver”).newInstance(); String dbPath = String.format( “jdbc:mysql://%s:%d/%s?user=%s&password=%s&characterEncoding=utf-8&” + “useUnicode=true”, ci.host, ci.port, ci.dbName, ci.user, ci.password); conn = java.sql.DriverManager.getConnection(dbPath); prepareTables(); } 表创建代码: private void prepareTables() throws SQLException { java.sql.Statement stat = conn.createStatement(); String query = “set names utf8”; stat.execute(query); query = “set character set utf8”; stat.execute(query); query = […]