JSP update有关问题
JSP update问题
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="connection.*,java.sql.*"%>
<html>
<head>
<title>updated score</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String name = request.getParameter("name");
String score = request.getParameter("score");
String subject = request.getParameter("subject");
dbconnection dbc = new dbconnection();
Connection conn = dbc.getconnection();
String sql = "update stu_score set name=?,score=?,subject=? where id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, request.getParameter("name"));
pst.setInt(2, Integer.parseInt(score));
pst.setString(3, subject);
pst.setInt(4, Integer.parseInt(id));
int result = pst.executeUpdate(sql);
if (result > 0) {
out.print("更新成功");
response.setHeader("refresh", "1;url=search_score.jsp");
} else {
out.print("更新失败");
}
%>
</body>
</html>
update语句在数据库成功执行,换其他查询语句可以正常执行
报错信息
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 '?,score=? where subject=?' at line 1
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 '?,score=? where subject=?' at line 1
------解决思路----------------------
它说你sql语句格式有问题,可是我看不出来哪里有问题,可能是很久没玩JDBC了吧。。。你刷新一下试试看,感觉是不是由于缓存引起的啊。。。
------解决思路----------------------
syntax 说明SQL本身有问题。
你看看name是不是乱码了
------解决思路----------------------
打出的错误为什么跟你的sql语句都不一样了。。。'?,score=? where subject=?..直接输出sql语句放到mysql运行下试试咯。
------解决思路----------------------
Hibernate注解怎样设置删除主键记录时同时删除所有外键记录,删除外键记录时不影响主键记录
------解决思路----------------------
使用问号的形式,你传的name是中文吧,试试英文好使不,这种情况普遍是乱码问题,SQL语句本身没问题。
------解决思路----------------------
用问号,解析不了的,你可以用个变量替换掉这些问号的
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="connection.*,java.sql.*"%>
<html>
<head>
<title>updated score</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String name = request.getParameter("name");
String score = request.getParameter("score");
String subject = request.getParameter("subject");
dbconnection dbc = new dbconnection();
Connection conn = dbc.getconnection();
String sql = "update stu_score set name=?,score=?,subject=? where id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, request.getParameter("name"));
pst.setInt(2, Integer.parseInt(score));
pst.setString(3, subject);
pst.setInt(4, Integer.parseInt(id));
int result = pst.executeUpdate(sql);
if (result > 0) {
out.print("更新成功");
response.setHeader("refresh", "1;url=search_score.jsp");
} else {
out.print("更新失败");
}
%>
</body>
</html>
update语句在数据库成功执行,换其他查询语句可以正常执行
报错信息
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 '?,score=? where subject=?' at line 1
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 '?,score=? where subject=?' at line 1
------解决思路----------------------
它说你sql语句格式有问题,可是我看不出来哪里有问题,可能是很久没玩JDBC了吧。。。你刷新一下试试看,感觉是不是由于缓存引起的啊。。。
------解决思路----------------------
syntax 说明SQL本身有问题。
你看看name是不是乱码了
------解决思路----------------------
打出的错误为什么跟你的sql语句都不一样了。。。'?,score=? where subject=?..直接输出sql语句放到mysql运行下试试咯。
------解决思路----------------------
Hibernate注解怎样设置删除主键记录时同时删除所有外键记录,删除外键记录时不影响主键记录
------解决思路----------------------
使用问号的形式,你传的name是中文吧,试试英文好使不,这种情况普遍是乱码问题,SQL语句本身没问题。
------解决思路----------------------
用问号,解析不了的,你可以用个变量替换掉这些问号的