int count = st.executeUpdate(sql); 为什么总是这一句报错
<%@pagelanguage="java"import="java.util.*,java.sql.*"pageEncoding="UTF-8"%><%Stringpa...
<%@ page language="java" import="java.util.*,java.sql.*" 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 'insertData.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 room=request.getParameter("room");
String birth=request.getParameter("birth");
String place=request.getParameter("place");
String ID=request.getParameter("ID");
String politics=request.getParameter("politics");
String tel=request.getParameter("tel");
String className="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/cmx_sql";
String user="root";
String password="";
Connection conn;
Statement st;
Class.forName(className);
conn=DriverManager.getConnection(url, user, password);
String sql="INSERT INTO student(birth) VALUES('"+birth+"') where stuID='1307142105'";
st = conn.createStatement(); // 创建用于执行静态sql语句的Statement对象
int count = st.executeUpdate(sql); // 执行插入操作的sql语句,并返回插入数据的个数
if(count>0)
{
response.sendRedirect("success.jsp");
}
conn.close(); //关闭数据库连接
%>
</body>
</html> 展开
<%
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 'insertData.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 room=request.getParameter("room");
String birth=request.getParameter("birth");
String place=request.getParameter("place");
String ID=request.getParameter("ID");
String politics=request.getParameter("politics");
String tel=request.getParameter("tel");
String className="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/cmx_sql";
String user="root";
String password="";
Connection conn;
Statement st;
Class.forName(className);
conn=DriverManager.getConnection(url, user, password);
String sql="INSERT INTO student(birth) VALUES('"+birth+"') where stuID='1307142105'";
st = conn.createStatement(); // 创建用于执行静态sql语句的Statement对象
int count = st.executeUpdate(sql); // 执行插入操作的sql语句,并返回插入数据的个数
if(count>0)
{
response.sendRedirect("success.jsp");
}
conn.close(); //关闭数据库连接
%>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询