海边的曼彻斯特 2016-05-04 09:28 采纳率: 0%
浏览 1277
已结题

JDBC关于数据更新的错误

错误信息是: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

代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here


<%
String name = request.getParameter("name");
name = name.trim();
if (name == null) {
name = "";
}
byte b[] = name.getBytes("ISO-8859-1");
name = new String(b);
String newmath = request.getParameter("mathGrade");
if (newmath == null) {
    newmath = "-100";
}
String newenglish = request.getParameter("englishGrade");
if (newenglish == null) {
    newenglish = "100";
}
String newpe = request.getParameter("peGrade");
if (newpe == null) {
    newpe = "-100";
}

Connection con = null;
Statement sql = null;
ResultSet rs = null;
String xingming, number;
int math, english, pe;
try {
    Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
    System.out.println("驱动程序加载错误");
}
try {
    con = DriverManager
            .getConnection(
                    "jdbc:mysql://localhost:3306/grade_db?useUnicode=true&characterEncoding=utf-8&useSSL=false",
                    "root", "123456");
    sql = con.createStatement();
    String condition1 = "UPDATE students SET englishGrade="
            + newenglish + "WHERE name=" + "'" + name + "'";
    String condition2 = "UPDATE students SET mathGrade=" + newmath
            + "WHERE name=" + "'" + name + "'";
    String condition3 = "UPDATE students SET peGrade=" + newpe
            + "WHERE name=" + "'" + name + "'";
    sql.executeUpdate(condition1);
    sql.executeUpdate(condition2);
    sql.executeUpdate(condition3);

%>

数据修改后的表的记录





<%
rs = sql.executeQuery("SELECT * FROM students");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
while (rs.next()) {
out.println("");
number = rs.getString(1);
out.println("");
xingming = rs.getString(2);
out.println("");
math = rs.getInt(3);
out.println("");
english = rs.getInt(4);
out.println("");
pe = rs.getInt(5);
out.println("");
out.println("");
}
out.println("
" + "学号" + "" + "姓名" + "" + "数学成绩" + "" + "英语成绩" + "" + "体育成绩" + "
" + number + "" + xingming + "" + math + "" + english + "" + pe + "
con.close();
} catch (SQLException e2) {
System.out.println(e2.getMessage());
}
%>


  • 写回答

3条回答

  • Shock_W 2016-05-04 09:31
    关注

    你一共有三个更新语句,因此,测试下,到底是哪个出现问题,再来解决

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元