用jsp连接数据库出错问题,求各位帮忙看看
不知道错在哪里?以下是代码<%@pagelanguage="java"contentType="text/html;charset=gb2312"import="java...
不知道错在哪里?以下是代码<%@ page language="java" contentType="text/html; charset=gb2312" import="java.sql.*"%> <!DOCTYPE html PUBLIC><html><head><title>登陆中</title></head><body> <% String DBDriver = "com.mysql.jdbc.Driver"; String DBUrl = "jdbc:mysql://localhost:3306/test01?useUnicode=true&useSSL=false"; String DBUser = "root"; String DBPass = ""; boolean getPermit = false; String username = request.getParameter("username"); String password = request.getParameter("password"); Connection con = null; Statement stmt = null; ResultSet rs = null; try { // 记得反射先 Class.forName(DBDriver); con = DriverManager.getConnection(DBUrl, DBUser, DBPass); String sql = ""; stmt = con.createStatement(); String sqlStr = "select * from stu where username='"+username+"' and password='"+password+"'"; System.out.println(sqlStr); rs = stmt.executeQuery(sqlStr); // 说明找到记录 if(rs.next()) { getPermit = true; } } catch (SQLException e) { System.out.println("连接数据库失败"); e.printStackTrace(); } finally { rs.close(); stmt.close(); con.close(); } if(getPermit) { request.getRequestDispatcher("success.jsp").forward(request, response); //response.sendRedirect("success.jsp"); } else { request.getRequestDispatcher("failure.jsp").forward(request, response); //response.sendRedirect("failure.jsp"); } %> </body> </html>
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询