JSP注册数据写入SQLserver2005报错,
错误信息:org.apache.jasper.JasperException: Unable to compile class for JSP:An error occurred at line: 47 in the jsp file: /check.jsp
rs cannot be resolved
44:
45: finally{
46: try{
47: rs.close() ;
48: pstmt.close() ;
49: conn.close() ;
50: }catch(Exception e){}
An error occurred at line: 150 in the generated java file
Syntax error, insert "}" to complete Block
An error occurred at line: 160 in the generated java file
Syntax error on token "}", delete this token
An error occurred at line: 161 in the generated java file
Syntax error, insert "}" to complete ClassBody
代码:<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<html>
<head><title>注册检测</title></head>
<jsp:useBean id="reg" scope="request" class="gg.Register"/>
<jsp:setProperty name="reg" property="*"/>
<body>
<%! // 定义若干个数据库的连接常量
public static final String DBDRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ;
public static final String DBURL = "jdbc:sqlserver://localhost:1433;database=login" ;
public static final String DBUSER = "sa" ;
public static final String DBPASS = "tan111000" ;
Connection conn = null ; // 数据库连接
PreparedStatement pstmt = null ; // 数据库预处理操作
%>
request.setCharacterEncoding("gbk") ;
<%
String username = request.getParameter("name");
String name = request.getParameter("age");
String password = request.getParameter("password");
%>
<%
try{
%>
<%
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
String sql = "insert into login(username,name,password) values('"+username+"','"+name+"','"+password+"')";
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
%>
}
<%
}catch(Exception e){}
finally{
try{
rs.close() ;
pstmt.close() ;
conn.close() ;
}catch(Exception e){}
if(reg.isValidate()){
%>
<jsp:forward page="success.jsp"/>
<%
} else {
%>
<jsp:forward page="zhuce.jsp"/>
<%
}
%>
</body>
</html> --------------------编程问答-------------------- 47行语法错啊。。。
Syntax error, insert "}" --------------------编程问答-------------------- finally{
try{
rs.close() ;
pstmt.close() ;
conn.close() ;
}catch(Exception e){}
if(reg.isValidate()){
%>
<jsp:forward page="success.jsp"/>
<%
} else {
%>
<jsp:forward page="zhuce.jsp"/>
<%
}
这一段的finally少了结束的"}". --------------------编程问答-------------------- 少写了一个}号。 --------------------编程问答-------------------- 同意楼上, --------------------编程问答-------------------- 怎么我看是没有定义rs对象,
插入操作也不用ResultSet,既然没有定义更不用提关闭了,所以出错呗
try{
rs.close() ; 《-----------------this,删
pstmt.close() ;
conn.close() ;
}catch(Exception e){} --------------------编程问答-------------------- 你都没有定义ResultSet 你关闭当然报错了!!! --------------------编程问答-------------------- rs在哪里定义的 而且提示说的是 少了"}" 检查下吧 --------------------编程问答-------------------- 同意三楼…… --------------------编程问答-------------------- 是JSP的语法错误啊 --------------------编程问答-------------------- 各种……
补充:Java , Web 开发