Rily
2015-06-27 17:58
request.setCharacterEncoding("utf-8");
String title = request.getParameter("title");
String container = request.getParameter("area2");
Connection conn = null;
Statement stmt = null;
String sql = "insert news1(title,container) values"
+ "(" + title + "," + container + ")";
try {
conn = DBhelper.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(sql);
response.sendRedirect(request.getContextPath() + "/success.jsp");
} catch (Exception ex) {
ex.printStackTrace();
}这是我用Servlet处理的,可是并没有写到MySQL中呀
报的是mysql语法错误,可能你的mysql版本不支持你的写法,最好还是规范写养成好习惯,insert into news1(title,container) values(\'" + title + "\',\'" + container + "\'),字符串用单引号引起来。
SQL语法错误:
String sql = "insert into news1 (title,container) values (\'" + title + "\',\'" + container + "\');";
建议使用PreparedStatement接口对SQL语句进行操作。
出错别激动,看清提示找问题。
求救啊
首先,先判断数据库能不能正常连接。(DBhelper工具类确认用户名,密码正确)
接着,确定对应数据库的表news1表中有字段title,container;
JAVA遇见HTML——Servlet篇
160609 学习 · 1093 问题
相似问题
回答 11
回答 2