<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.sql.*"%>
<%
request.setCharacterEncoding("UTF-8");
String Title=request.getParameter("Title");
String url="jdbc:mysql://127.0.0.1:3306/"+dbName+"?user="+userName+"&password="+userPasswd+"&useUnicode=true&characterEncoding=utf-8"; try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
stmt.executeUpdate("insert into Notice(Title) values('"+Title+"')");
stmt.close();
conn.close();
}catch (SQLException e){
out.print("error"+e);
}
out.print(Title);
print能正确显示中文,存入mysql后乱码。
<%@ page import="java.sql.*"%>
<%
request.setCharacterEncoding("UTF-8");
String Title=request.getParameter("Title");
String url="jdbc:mysql://127.0.0.1:3306/"+dbName+"?user="+userName+"&password="+userPasswd+"&useUnicode=true&characterEncoding=utf-8"; try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
stmt.executeUpdate("insert into Notice(Title) values('"+Title+"')");
stmt.close();
conn.close();
}catch (SQLException e){
out.print("error"+e);
}
out.print(Title);
print能正确显示中文,存入mysql后乱码。
MySQL 中文显示乱码
character_sets gb2312 big5 cp1251 cp1257 croat czech danish dec8 dos estonia euc_kr gbk german1 greek hebrew hp8 hungarian koi8_ru koi8_ukr latin1 latin1_de latin2 latin5 sjis swe7 tis620 ujis usa7 win1250 win1251ukr win1251
这个是万网空间提供的数据库,我好像没权限改的。
这种转换的代码应该很多吧。