mysql 中文问题

来源:互联网 发布:淘宝c店保证金怎么办 编辑:程序博客网 时间:2024/05/17 04:30

在与mysql链接后,发现,当查询的时候,中文的就是没用,后来发现,链接的语句应该这样写

con = java.sql.DriverManager.getConnection(dbUrl + "?user=" + dbUser + "&password=" + dbPwd + "&useUnicode=true&characterEncoding=utf8");  要将编码方式写进去

 

 

但是写进去后,当我插入中文数据的时候,仍然是乱码,后来发现应该这样插入:

selectSql = "insert into t_notice(id,type, title,content,status,release_time) values(?,?,?,?,?,UNIX_TIMESTAMP(NOW()))";
    prepStmt = con.prepareStatement(selectSql);
    prepStmt.setInt(1, id);
    prepStmt.setInt(2, type);
    prepStmt.setString(3, title);
    prepStmt.setString(4, context);
    prepStmt.setString(5, statue);
    int resulrt = prepStmt.executeUpdate();

 

而不能这样直接插入

selectSql = "insert into t_notice(id,type, title,content,status,release_time) values("+id+

","+type+","+title+","+context+","+statue+",UNIX_TIMESTAMP(NOW()))";

原创粉丝点击