Py学习  »  DATABASE

尝试关闭MySQL连接时出错

Moladhh • 4 年前 • 545 次点击  

当我试图关闭MySQL连接时,我的页面显示为空白。我是不是把接头关在正确的地方了?用户登录(正在工作),但是在userprofile.jsp中关闭MySQL连接似乎有错误。我认为这与连接的关闭有关,因为它在没有连接的情况下工作

重定向到用户配置文件页的登录类

    try (PrintWriter out = response.getWriter()) {

        String name = request.getParameter("name");
        String pass = request.getParameter("pass");
        MyDb1 db = new MyDb1();
      Connection con = db.getCon();
      Statement stmt = con.createStatement();
     ResultSet rs = stmt.executeQuery("select uid,name,pass from lauraccc_fyp.register where email = '"+name+"' and  pass = '"+pass+"'");

     while ((rs.next())) {

        String uid = rs.getString("uid");


             HttpSession session=request.getSession(); 
          session.setAttribute("name",uid);

        RequestDispatcher dispatcher = request.getRequestDispatcher("/userprofile.jsp");
            dispatcher.forward(request, response);
         return;



  } catch (SQLException ex) {
       }




</head>
<body>

<div class="fh5co-loader"></div>

<%

try {

    String session_id =null;
    HttpSession session1=request.getSession(false); 

    if(session1!=null) {  
        session_id=(String)session1.getAttribute("name");  
    }

    Class.forName("com.mysql.jdbc.Driver");

    Connection  con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lauraccc_fyp", "lauraccc", "*");
    Statement stmt = con.createStatement();

    ResultSet rs = stmt.executeQuery("select * from register where uid='"+session_id+"'");
    rs.next();

    String name = rs.getString("name");
    con.close();

}catch(Exception e) {
    out.println(e);
}
<h1>Welcome back <%out.print(name);%></h1>
%>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52694
 
545 次点击  
文章 [ 1 ]  |  最新文章 4 年前
DanB
Reply   •   1 楼
DanB    5 年前

你的页面是空白的?我想这是因为一切都很好。在try-catch块中,根本没有输出。