utf8值从表单文本框插入到mysql数据库中

时间:2014-10-01 10:26:24

标签: jsp

当想要将utf-8插入mysql数据库时,jdbc不提供事实值。给了??????

<%
    String conUrl="jdbc:mysql://localhost:3306/school1?useEncoding=true&amp;characterEncoding=UTF-8";
    String userName="root";
    String pass="system";
    Class.forName("com.mysql.jdbc.Driver");
    con=DriverManager.getConnection(conUrl,userName,pass);

    String firstname = new String(request.getParameter("fName").getBytes("ISO-8859-1"),"UTF-8"); 
    String email = new String(request.getParameter("eMail").getBytes("ISO-8859-1"),"UTF-8");    System.out.print(firstname); 
    System.out.print(email); 
try { 
  st.executeUpdate("insert into std values('"+firstname+"','"+email+"')"); 
}
catch(Exception e1) { 
  System.out.print(e1); 
} %>

0 个答案:

没有答案