[英]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.