修复登录数据库性能错误
This commit is contained in:
@@ -25,11 +25,10 @@
|
||||
String users = request.getParameter("inputUser");
|
||||
String pass = request.getParameter("inputPassword");
|
||||
boolean flag = false;
|
||||
PreparedStatement sql = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = null;
|
||||
PreparedStatement vipsql = null;
|
||||
ResultSet viprs = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
session.setMaxInactiveInterval(1440);
|
||||
%>
|
||||
@@ -40,6 +39,10 @@
|
||||
String use = "root";
|
||||
String password = "";
|
||||
Class.forName(driver);
|
||||
try {
|
||||
PreparedStatement sql = null;
|
||||
Connection conn = null;
|
||||
ResultSet rs = null;
|
||||
conn = DriverManager.getConnection(url, use, password);
|
||||
sql = conn.prepareStatement("select * from user where userName=? and password=?");
|
||||
sql.setString(1, users);
|
||||
@@ -50,9 +53,18 @@
|
||||
}
|
||||
rs.close();
|
||||
sql.close();
|
||||
conn.close();
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
%>
|
||||
<%
|
||||
try {
|
||||
PreparedStatement vipsql = null;
|
||||
ResultSet viprs = null;
|
||||
Connection conn = null;
|
||||
vipsql = conn.prepareStatement(
|
||||
"select userName,case when VIP = 1 then 'VIP用户' else '普通用户' end as VIP,case when Administrator = 1 then '管理员' else '' end as Administrator from show_user where userName=?");
|
||||
vipsql.setString(1, users);
|
||||
@@ -63,6 +75,9 @@
|
||||
session.setAttribute("VIPuser", vipinfo);
|
||||
session.setAttribute("Adminuser", adminfo);
|
||||
}
|
||||
viprs.close();
|
||||
vipsql.close();
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -80,11 +95,9 @@
|
||||
<jsp:forward page="login_fail.jsp" />
|
||||
<%
|
||||
}
|
||||
viprs.close();
|
||||
vipsql.close();
|
||||
rs.close();
|
||||
sql.close();
|
||||
conn.close();
|
||||
|
||||
|
||||
|
||||
%>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
|
||||
<%@ page language="java" import="java.util.*"
|
||||
contentType="text/html;charset=utf-8"%>
|
||||
<%
|
||||
String path = request.getContextPath();
|
||||
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
|
||||
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
|
||||
+ path + "/";
|
||||
%>
|
||||
<%@page import="java.sql.Connection"%>
|
||||
<%@page import="java.sql.*"%>
|
||||
@@ -36,12 +38,9 @@ String str_date2 = currentTime.toString(); //将Date型日期时间转换成字
|
||||
String user = "root";
|
||||
String password = "";
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement sql = null;
|
||||
String counter = null;
|
||||
Class.forName(driverClass);
|
||||
conn = DriverManager.getConnection(url, user, password);
|
||||
Statement stmt = conn.createStatement();
|
||||
|
||||
Object user0 = session.getAttribute("actualuser");
|
||||
/* out.println("欢迎"+user0);//输出当前session用户 */
|
||||
%>
|
||||
@@ -61,27 +60,42 @@ String str_date2 = currentTime.toString(); //将Date型日期时间转换成字
|
||||
<%
|
||||
counter = getIpAddr(request);
|
||||
try {
|
||||
Connection conn = null;
|
||||
PreparedStatement sql = null;
|
||||
conn = DriverManager.getConnection(url, user, password);
|
||||
Statement stmt = conn.createStatement();
|
||||
sql = conn.prepareStatement("update counter set visitCount=visitCount+1");
|
||||
int rtn = sql.executeUpdate();
|
||||
stmt.close();
|
||||
sql.close();
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Connection conn = null;
|
||||
PreparedStatement sql = null;
|
||||
conn = DriverManager.getConnection(url, user, password);
|
||||
Statement stmt = conn.createStatement();
|
||||
sql = conn.prepareStatement("insert into iplist(IP,times,userName)values(?,?,?)");
|
||||
sql.setString(1, counter);
|
||||
sql.setString(2, str_date1);
|
||||
sql.setString(3, (String) user0);
|
||||
int rtn = sql.executeUpdate();
|
||||
stmt.close();
|
||||
sql.close();
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
%>
|
||||
<%
|
||||
stmt.close();
|
||||
sql.close();
|
||||
conn.close();
|
||||
|
||||
%>
|
||||
登录成功.
|
||||
<br>
|
||||
<%
|
||||
response.setHeader("refresh", "0;url=../mainframe.jsp");
|
||||
%>
|
||||
登录成功. <br>
|
||||
<% response.setHeader("refresh","0;url=../mainframe.jsp");%>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user