stmt.executeUpdate(XX)问题,求助。。。
Exceptionorg.apache.jasper.JasperException: An exception occurred processing JSP page [/charu.jsp] at line [34]
31: String Grade=request.getParameter("Grade");
32: String Crad_num=request.getParameter("Crad_num");
33: String sql2="insert into User_information values ('"+Sno+"','"+User_name+"','"+Sex+"','"+Professional+"','"+Grade+"','"+Crad_num+"')";
34: stmt.executeUpdate(sql2);
35: %>
36: 娣诲姞璇剧▼淇℃伅鎴愬姛!
37: <% } %>
代码如下
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<%@page import ="java.sql.*" %>
<html>
<head><title>添加卡号信息</title></head>
<body>
<%
request.setCharacterEncoding("UTF-8") ;
String Sno=request.getParameter("Sno") ;
int i=0;
String jdbcDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(jdbcDriver);//加载数据库驱动
String url="jdbc:sqlserver://localhost:1433;DatabaseName=school_card";//声明数据库Test的URL
String user="sa";//数据库用户名
String password="123456";//数据库密码
Connection con=DriverManager.getConnection(url,user,password);//建立数据库连接,获得连接对象
Statement stmt=con.createStatement () ;
String sql1="SELECT Sno FROM User_information" ;
ResultSet rs=stmt.executeQuery(sql1) ;
while (rs.next())
{
if (Sno.equals(rs.getString("Sno")))i++;
}
if(i!=0) {
%>该编号已存在,请核对后重新输入!
<% } else{
String User_name=request.getParameter ("User_name");
String Sex= request.getParameter("Sex");
String Professional=request.getParameter("Professional");
String Grade=request.getParameter("Grade");
String Crad_num=request.getParameter("Crad_num");
String sql2="insert into User_information values ('"+Sno+"','"+User_name+"','"+Sex+"','"+Professional+"','"+Grade+"','"+Crad_num+"')";
stmt.executeUpdate(sql2);
%>
添加课程信息成功!
<% } %>
<% stmt.close();
con.close();
%>
</body>
</html>