数据库实现修改数据功能是出现列名'studentWeight'无效错误,该如何修改?
<%@page import="java.sql.*"%> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'updateStudentCheck.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% String id=new String(request.getParameter("id")); byte b[]=id.getBytes("ISO-8859-1"); id=new String(b,"UTF-8"); String studentName1=request.getParameter("studentName"); byte b1[]=studentName1.getBytes("ISO-8859-1"); studentName1=new String(b1,"UTF-8"); String studentSex1=request.getParameter("studentSex"); byte b2[]=studentSex1.getBytes("ISO-8859-1"); studentSex1=new String(b2,"UTF-8"); String studentAge1=request.getParameter("studentAge"); byte b3[]=studentAge1.getBytes("ISO-8859-1"); studentAge1=new String(b3,"UTF-8"); String studentWeight1=request.getParameter("studentWeight"); byte b4[]=studentWeight1.getBytes("ISO-8859-1"); studentWeight1=new String(b4,"UTF-8"); Connection conn=null; Statement stmt=null; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url="jdbc:sqlserver://localhost:1433;databasename=student"; String user="stu"; String password="stu"; conn= DriverManager.getConnection(url,user,password); stmt=conn.createStatement(); String sql="update student set studentName='"+studentName1+"',studentSex='"+studentSex1+ "',studentAge="+studentAge1+",studentWeight="+studentWeight1+" where studentNumber='"+id+"'"; stmt.executeUpdate(sql); conn.close(); stmt.close(); %> <h3>修改完成!</h3> </body> </html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢,看到了!
确实是无效啊,两个列名都不一致,sql 写的 studentWeight,数据库的是stuedntWeight
可以把你的执行SQL语句打印出来看看