u014678907 2015-04-15 12:30 采纳率: 0%
浏览 2045

jsp 应用程序 finally里的 rs pstmt conn出错


登录验证界面

<%
try{
Connection conn =null;
PreparedStatement pstmt =null;
ResultSet rs=null;
String driverName ="com.sql.jdbc.Driver";
String dbName="user";
String url1="jdbc:sql://localhost/"+dbName;
String url2="?user=sa&password=lx13784429739";
String url3="&Unicode=true&characterEncoding=GB2312";
String url=url1+url2+url3;
Class.forName(driverName);
conn=DriverManager.getConnection(url);
request.setCharacterEncoding("GB2312");
String name=request.getParameter("username");
String pw=request.getParameter("pass");
String sql="select * from user_b where(uname=?andupassword=?) ";
pstmt =conn.prepareStatement(sql);
pstmt.setString(1,name);
pstmt.setString(2,pw);
rs=pstmt.executeQuery();
if(rs.next()){
%><%=name%>:登陆成功!<br><%
}
else{%>
<%=name %>:登录失败!<br><%}
}catch(Exception e)
 {%>
              出现异常错误!<br><%=e.getMessage()%>
<%}
  finally{
        if(rs!=null){rs.close();}
        if(pstmt!=null){pstmt.close();}
        if(conn!=null){conn.close();}
}%>


提示错误:rs cannot be resolved to a variable。。。。

个人感觉是变量定义的问题,希望大神不吝赐教

  • 写回答

1条回答 默认 最新

  • liukai123 2015-04-15 12:45
    关注

    不是什么变量的问题 你的 statement result connection 的定义 应该放在try的外面 放在里面 你还try什么。。。

    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常