简体   繁体   English

当我尝试关闭MySQL连接时出错

[英]Error when I try to close MySQL connection

When I try to close a MySQL connection, my page shows up as blank. 当我尝试关闭MySQL连接时,我的页面显示为空白。 Am I placing the closing of the connection in the right place? 我是否将关闭连接的位置正确? The user logs in (which is working), but then there seems to be an error with closing the MySQL connection in the userprofile.jsp. 用户登录(正在运行),但是在userprofile.jsp中关闭MySQL连接似乎出现了错误。 I think it is something to do with the closing of the connection as it is working without it 我认为这与关闭连接有关,因为如果没有它,它将正常工作

Login class which redirects to the userprofile page 重定向到用户配置文件页面的登录类

    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>
%>

Your page is blank? 您的页面空白? I think this is because everything is fine. 我认为这是因为一切都很好。 In your try catch block, there is no output at all. 在您的try catch块中,根本没有输出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (JOOQ) 当我尝试编译项目时出现与 Mysql 的连接错误 - (JOOQ) When I try to compile project get connection error with Mysql 当我尝试结束通话时 WebRTC 崩溃(关闭连接) - WebRTC crash when I try to end a call (close connection) 当我尝试关闭键盘时折叠 android - Collapse android when I try to close keyboard 当我尝试关闭搜索视图时出现奇怪的行为 - Strange behavior when I try to close a searchview 这会尝试使用资源关闭我的连接吗? - Will this try with resources close my Connection? 当我尝试在连接时进行设置时,将mysql中的Datetime和时间戳从默认时区转换为Java中的UTC无法正常工作 - Convert Datetime and timestamp in mysql from default timezone to UTC in Java is not working when I try to set it at time of connection 我得到一个数据库被锁定的异常,我尝试关闭连接和语句,但这是 try 块中无法访问语句的问题 - I get an exception that the database is locked and I try to close connection and statement but here is the problem unreachable statement in try block 使用SessionFactoryUtils时是否应该关闭连接 - Should I close connection when using SessionFactoryUtils 使用Java Servlet时何时打开和何时关闭mysql连接? - When to open and when to close the mysql connection while using Java servlets? 尝试将应用程序重新部署到tomcat7服务器时出现连接重置错误 - Connection reset error when I try to redeploy application to tomcat7 server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM