错误描述:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to
use near 'gender='?”·' address='?????·' tel='15277886670' email='[email protected]' birthday=null' at line 1
Query: update customer set name=? gender=? address=? tel=? email=? birthday=? Parameters: [何膨, 男, 上海, 15277886670, [email protected], null]Servlet代码:
private void updateCustomer(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
Customer customer = new Customer();
CrmService crmService = new CrmService();
Enumeration<String> enums = request.getParameterNames();
try {
while(enums.hasMoreElements()){
String key = (String) enums.nextElement();
String [] values = request.getParameterValues(key);
ConvertUtils.register(
new DateLocaleConverter("yyyy-MM-dd"),
java.util.Date.class);
BeanUtils.setProperty(customer,key,values);
}
crmService.upDateCustomer(customer);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("message","更新客户信息失败");
request.getRequestDispatcher("/WEB- INF/jsp/message.jsp").forward(request,response);
}
}Service代码:
//更新客户信息
public void upDateCustomer(Customer customer) throws Exception{
try {
crmDao.upDateCustomer(customer);
} catch (SQLException e) {
e.printStackTrace();
throw new UpdateException();
}
}Dao代码:
public void upDateCustomer(Customer customer) throws SQLException{
QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());
String sql = "update customer set name=? gender=? address=? tel=? email=? birthday=? ";
try {
runner.update(sql,
new Object[]{customer.getName(),
customer.getGender(),
customer.getAddress(),
customer.getTel(),
customer.getEmail(),
customer.getBirthday()});
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw e;
}
}数据库结构表:
create table if not exists customer(
id int auto_increment primary key,
name varchar(20) not null,
gender varchar(6) not null,
address varchar(30) not null,
tel varchar(11) not null,
email varchar(20) not null,
birthday date not null
);
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to
use near 'gender='?”·' address='?????·' tel='15277886670' email='[email protected]' birthday=null' at line 1
Query: update customer set name=? gender=? address=? tel=? email=? birthday=? Parameters: [何膨, 男, 上海, 15277886670, [email protected], null]Servlet代码:
private void updateCustomer(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
Customer customer = new Customer();
CrmService crmService = new CrmService();
Enumeration<String> enums = request.getParameterNames();
try {
while(enums.hasMoreElements()){
String key = (String) enums.nextElement();
String [] values = request.getParameterValues(key);
ConvertUtils.register(
new DateLocaleConverter("yyyy-MM-dd"),
java.util.Date.class);
BeanUtils.setProperty(customer,key,values);
}
crmService.upDateCustomer(customer);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("message","更新客户信息失败");
request.getRequestDispatcher("/WEB- INF/jsp/message.jsp").forward(request,response);
}
}Service代码:
//更新客户信息
public void upDateCustomer(Customer customer) throws Exception{
try {
crmDao.upDateCustomer(customer);
} catch (SQLException e) {
e.printStackTrace();
throw new UpdateException();
}
}Dao代码:
public void upDateCustomer(Customer customer) throws SQLException{
QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());
String sql = "update customer set name=? gender=? address=? tel=? email=? birthday=? ";
try {
runner.update(sql,
new Object[]{customer.getName(),
customer.getGender(),
customer.getAddress(),
customer.getTel(),
customer.getEmail(),
customer.getBirthday()});
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw e;
}
}数据库结构表:
create table if not exists customer(
id int auto_increment primary key,
name varchar(20) not null,
gender varchar(6) not null,
address varchar(30) not null,
tel varchar(11) not null,
email varchar(20) not null,
birthday date not null
);
。加个过滤器就可以解决。
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");//加上
......
......
}
Dao代码中
String sql = "update customer set name=? gender=? address=? tel=? email=? birthday=? ";
--》
String sql = "update customer set name=?,gender=?,address=?,tel=?,email=?, birthday=? ";