提示testservlet.java:22为报告异常java.sql.SQLException;必须对其进行捕捉或声明以便抛出if(dbc.islogin(username,password))
解决方案 »
- 请过来人告诉我一些关于java学习的适合你自己的且经过实际验证过的好的学习方法和学习经验,先谢谢了!
- 无法将<s:Form>解析组件执行
- 谁需要scjp考试券请于我联系
- 为什么EJB有生命周期?EJB3.0有没有?
- struts+hibernate读取数据问题(在线等待……)
- 请求帮助 无效的游标状态
- ibatis中sqlMapConfig的settings设置问题 在线等
- 关于用jsp处理sql server图像存取的问题,急!!!
- [springmvc]返回ModelAndView,视图解析不到jsp,有人知道原因么?
- 弱弱的问个sql语句
- 【求助】 hibernate 的查询问题
- window xp 下安装 Ubuntu,装过的进
你在方法的throws列表后面加上SQLException
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
.....
}
这是个什么错误啊
servlet doPost方法i是没有抛出java.sql.SQLException的public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
String username = request.getParameter("username");
String password = request.getParameter("password");
DBConnection dbc = new DBConnection();
try{
if(dbc.islogin(username,password))
response.sendRedirect("main.jsp");
else
response.sendRedirect("regedit.jsp");
}catch(SQLException e ){}
HttpSession session = request.getSession(true);
session.removeAttribute("username");
session.setAttribute("username",username);
}
这样看看
public boolean islogin(String username,String password)throws SQLException
{
int count=0;
sql = "select count(*) from table1 where username=? and password=?";
prst = conn.prepareStatement(sql);
prst.setString(1,"username");
prst.setString(2,"password");
rs = prst.executeQuery();
while(rs.next())
{
count=rs.getInt(1);
}
return count>0?true:false;
}
}
里面要用try catch
你的isLogin方法声明的时候设定抛出异常public boolean islogin(String username,String password)throws SQLException
但你在servlet里用这个方法时没有将异常捕获
在 isLogin() 方法用try-catch包围