所有编码方式都已经统一为GBK了(包括数据表),还是乱码啊,无限纠结ingprotected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession(false);
String id=session.getAttribute("id").toString();
String Address=request.getParameter("address");
Information info=new Information();
info.setInfo(id, "Address", Address);//更新数据表中Address属性的值
request.setAttribute("success", "修改信息成功!");
PrintWriter out = response.getWriter();
try {
//TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ModifyInfo</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet ModifyInfo at " + request.getContextPath () + "</h1>");
out.println("<br>"+Address);
out.print("<br>"+info.getInfo(id, "Address"));//获取数据表中Address属性的值,就是这里中文显示乱码
out.println("</body>");
out.println("</html>");
} finally {
out.close();
} }
throws ServletException, IOException {
HttpSession session=request.getSession(false);
String id=session.getAttribute("id").toString();
String Address=request.getParameter("address");
Information info=new Information();
info.setInfo(id, "Address", Address);//更新数据表中Address属性的值
request.setAttribute("success", "修改信息成功!");
PrintWriter out = response.getWriter();
try {
//TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ModifyInfo</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet ModifyInfo at " + request.getContextPath () + "</h1>");
out.println("<br>"+Address);
out.print("<br>"+info.getInfo(id, "Address"));//获取数据表中Address属性的值,就是这里中文显示乱码
out.println("</body>");
out.println("</html>");
} finally {
out.close();
} }
解决方案 »
- 如何还原master数据库
- 简单SQL,高分相送
- sql查询/....
- 求一SQL语句(在线等)
- 关于sql语句 grouy by
- ASP查询大型数据库出错,请高手指点!
- **SQL 个人版,怎么新建一个“SQL Server组”后,再在这个组里附加数据库?救命啊**
- 关于触发器的。。。
- 在线求救,写一个类似交叉结果集的sql (最好结果集能保存在一个table中或者以视图的样式存储)
- 在VFP中我用的是DBF数据库,如何在SQL语句中将CHAR类型转换成INT类型?不好意思没用过VFP的DBF数据库的SQL语句转换类型
- 请问MYSQL中的key的用法是什么样的
- SQLserver2000个人版(WIN7旗舰)打SP4出现问题了,请教高手!!!
import java.sql.*;
import Database.DatabaseConnection;
public class Information {
private String info;
//private boolean flag;
public Information(){
}
public void setInfo(String id, String property, String value) {
DatabaseConnection c=new DatabaseConnection();
Connection con=null;
Statement smt=null;
con=c.getMysqlConnection("together", "root", "123");
String sql="UPDATE studentinfo SET "+property+"= '"+value+"' WHERE StudentID='"+id+"'";
try{
smt=con.createStatement();
smt.executeUpdate(sql);
con.close();
smt.close();
}catch( SQLException e){
System.out.println("=SQLException:"+e.getMessage());
}
}
}
package Database;
import java.sql.*;
public class DatabaseConnection {
public Connection getMysqlConnection(String DatabaseName,String user,String password){
Connection con=null;
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/"+DatabaseName+"?user="+user+"&password="+password;
try{
Class.forName(driver);
}catch(ClassNotFoundException e){
System.out.println("Class.forName:"+e.getMessage());
}
try{
con=DriverManager.getConnection(url);
}catch(SQLException e){
System.out.println("=SQLException:"+e.getMessage());
}
return con;
}
}