jfinal编码问题及解决

使用jfinal出现了常见的编码问题情况

public void test() {
Random r = new Random();

try {
Connection conn = createConnection();
Statement st = conn.createStatement();
String sql = "insert into encode_test values(" + r.nextInt() + ", '汉字')";
System.out.println("SQL: " + sql);
st.execute(sql);
st.close();
conn.close();

conn = DbKit.getConfig().getConnection();
st = conn.createStatement();
sql = "insert into encode_test values(" + r.nextInt() + ", '汉字测试c3p0')";
System.out.println("SQL: " + sql);
st.execute(sql);
st.close();
conn.close();


sql = "insert into encode_test values(" + r.nextInt() + ", '汉字')";
Db.update(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
renderText("OK");
}

用以上原始的代码是正确的,但是使用druidplugin时出现了问题

public void login(){
        User user=getModel(User.class);
        user.save();
        render("/result.html");
        System.out.println("ok!");

jfinal编码问题及解决_第1张图片

解决办法

prop加上

jdbcUrl = jdbc:mysql://localhost:3306/wsy_student?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull

即可解决问题

这里写图片描述

你可能感兴趣的:(Jfinal)