stringbuffer mysql_java中StringBuffer插入mysql乱码问题

本文探讨了一种在实体类中采用StringBuffer以提高性能的方法,特别是在处理如自我介绍等可能包含大量文本信息的字段时。通过示例代码展示了如何在Servlet中接收并处理这些大型字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

你意思是 我实体类中还是用String类型 然后在servlet中用StringBuffer接受?

可这样的话就没必要用StringBuffer了啊 我考虑的是性能 因为自我介绍那一项可能会有很多内容

另外,我用StringBuffer保存时 数据库中那列的类型是另外中大容量类型的

部分代码如下:

实体类:

package entity;

import java.util.Date;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.Table;

import javax.persistence.Temporal;

import javax.persistence.TemporalType;

@Entity

@Table(name="t_customer")

public class Customer

{

private int c_id;

private String c_name;

private String c_password;

private String c_sex;

private Date c_birthday;

private String c_education;

private StringBuffer c_intorduce;

private String c_favor;

@Id

@GeneratedValue

public int getC_id() {

return c_id;

}

public void setC_id(int cId) {

c_id = cId;

}

public String getC_name() {

return c_name;

}

public void setC_name(String cName) {

c_name = cName;

}

public String getC_password() {

return c_password;

}

public void setC_password(String cPassword) {

c_password = cPassword;

}

public String getC_sex() {

return c_sex;

}

public void setC_sex(String cSex) {

c_sex = cSex;

}

@Temporal(TemporalType.DATE)

public Date getC_birthday() {

return c_birthday;

}

public void setC_birthday(Date cBirthday) {

c_birthday = cBirthday;

}

public String getC_education() {

return c_education;

}

public void setC_education(String cEducation) {

c_education = cEducation;

}

public StringBuffer getC_intorduce() {

return c_intorduce;

}

public void setC_intorduce(StringBuffer cIntorduce) {

c_intorduce = cIntorduce;

}

public String getC_favor() {

return c_favor;

}

public void setC_favor(String cFavor) {

c_favor = cFavor;

}

}

servlet:

@Override

protected void doGet(HttpServletRequest req, HttpServletResponse rep)

throws ServletException, IOException {

req.setCharacterEncoding("GBK");

rep.setContentType("text/html;charset=GBK");

PrintWriter out=rep.getWriter();

String c_name=req.getParameter("c_name");

String c_password=req.getParameter("c_password");

String c_sex=req.getParameter("c_sex");

String year=req.getParameter("year");

String month=req.getParameter("month");

String date=req.getParameter("date");

String c_birthday=year+"-"+month+"-"+date;

SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");

Date c_birth=new Date();

try {

c_birth = df.parse(c_birthday);

}

catch (ParseException e) {

e.printStackTrace();

}

String c_edu=req.getParameter("c_edu");

String c_favor=req.getParameter("c_favor");

/*StringBuffer c_intorduce=new StringBuffer();

c_intorduce.append(req.getParameter("c_intorduce"));

System.out.println(c_intorduce.toString());*/

String c_intorduce=req.getParameter("c_intorduce");

Customer customer=new Customer();

customer.setC_name(c_name);

customer.setC_password(c_password);

customer.setC_sex(c_sex);

customer.setC_birthday(c_birth);

customer.setC_education(c_edu);

customer.setC_favor(c_favor);

customer.setC_intorduce(c_intorduce);

CustomerDao dao=new CustomerDao();

dao.addcustomer(customer);

out.flush();

out.close();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值