异常处理:jsp页面向mysql插入数据。求各位看看哪里出错!!!
这是我的代码:<%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%><%@pageimport="j...
这是我的代码:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<center>
<h1>登陆操作</h1>
<hr>
<%! // 定义若干个数据库的连接常量
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
public static final String DBURL = "jdbc:mysql://localhost:3306/web" ;
public static final String DBUSER = "root" ;
public static final String DBPASS = "000000" ;
%>
<%
Connection conn = null ; // 数据库连接
Statement stmt = null ; // 数据库预处理操作
%>
<%
String houseid=request.getParameter("houseid");//内置对象
String keeperid=request.getParameter("keeperid");
int housesize=Integer.parseInt(request.getParameter("housesize"));
int firstyear=Integer.parseInt(request.getParameter("firstyear"));
String picture=request.getParameter("picture");
System.out.println("iiiii");
%>
<%
try{
%>
<%
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
String sql="insert into house (houseid,keeperid,housesize,firstyear) values ('"+houseid+"','"+keeperid+"',"+housesize+","+firstyear+",'"+picture+"')";
stmt=conn.createStatement();
int i = stmt.executeUpdate(sql);
if(i>0){
%>
<jsp:forward page="update_success.jsp">;
<%
}else{
%>
<jsp:forward page="update_failure.jsp">
<%
}
%>
<%
}catch(Exception e) {
e.printStackTrace() ;
}
finally{
try{
stmt.close() ;
conn.close() ;
} catch(Exception e){}
}
%>
</center>
</body>
</html>
报错:
org.apache.jasper.JasperException: /update.jsp(42,44) Expecting "jsp:param" standard action with "name" and "value" attributes 展开
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<center>
<h1>登陆操作</h1>
<hr>
<%! // 定义若干个数据库的连接常量
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
public static final String DBURL = "jdbc:mysql://localhost:3306/web" ;
public static final String DBUSER = "root" ;
public static final String DBPASS = "000000" ;
%>
<%
Connection conn = null ; // 数据库连接
Statement stmt = null ; // 数据库预处理操作
%>
<%
String houseid=request.getParameter("houseid");//内置对象
String keeperid=request.getParameter("keeperid");
int housesize=Integer.parseInt(request.getParameter("housesize"));
int firstyear=Integer.parseInt(request.getParameter("firstyear"));
String picture=request.getParameter("picture");
System.out.println("iiiii");
%>
<%
try{
%>
<%
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
String sql="insert into house (houseid,keeperid,housesize,firstyear) values ('"+houseid+"','"+keeperid+"',"+housesize+","+firstyear+",'"+picture+"')";
stmt=conn.createStatement();
int i = stmt.executeUpdate(sql);
if(i>0){
%>
<jsp:forward page="update_success.jsp">;
<%
}else{
%>
<jsp:forward page="update_failure.jsp">
<%
}
%>
<%
}catch(Exception e) {
e.printStackTrace() ;
}
finally{
try{
stmt.close() ;
conn.close() ;
} catch(Exception e){}
}
%>
</center>
</body>
</html>
报错:
org.apache.jasper.JasperException: /update.jsp(42,44) Expecting "jsp:param" standard action with "name" and "value" attributes 展开
2个回答
展开全部
insert into house (houseid,keeperid,housesize,firstyear) values ('"+houseid+"','"+keeperid+"',"+housesize+","+firstyear+")"; 字段的数量和值的数量不对应.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上正解,不过参数最好别用这种方式来设置 容易有sql注入漏洞
追问
String sql="insert into house (houseid,keeperid,housesize,firstyear,picture) values ('"+houseid+"','"+keeperid+"',"+housesize+","+firstyear+",'"+picture+"')";
我改了之后还是报的相同的错误,到底怎么改呢?
追答
values里面(?,?,?,?,?) 然后获取到了preparedStatement对象后 就给它设值
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询