"loginmid.jsp" to update the table.
<%@ page language="java" import="java.sql.*;"%>
<%
String userName = request.getParameter("userName");
String password = request.getParameter("password");
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:
mysql://localhost:3306/";;
String dbName = "userdetails";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String userPassword = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,username,userPassword);
Statement st = conn.createStatement();
String strQuery = "select * from user where username='"+userName+"' and password='"+password+"'";
out.println(strQuery);
ResultSet rs = st.executeQuery(strQuery);
int logoutcount=0;
int logincount=0;
if(rs.next())
{
if(rs.getInt("logincount")>0 && rs.getInt("logincount")<10)
{
logincount = rs.getInt("logincount") +1;
String strinsertQuery = "update user set logincount='"+logincount+"' where username='"+userName+"' and password='"+password+"'";
int i = st.executeUpdate(strinsertQuery);
session.setAttribute("userid",userName);
response.sendRedirect("welcome.jsp");
}
if(rs.getInt("logoutcount")>0 && rs.getInt("logoutcount")<10)
{
logoutcount = rs.getInt("logoutcount") +1;
String strinsertQuery = "update user set logoutcount='"+logoutcount+"' where username='"+userName+"' and password='"+password+"'";
int i = st.executeUpdate(strinsertQuery);
session.setAttribute("userid",userName);
response.sendRedirect("welcome.jsp");
}
if(rs.getInt("logoutcount")==10)
{
String strdelQuery = "delete * from user where username='"+userName+"' and password='"+password+"'";
int i = st.executeUpdate(strdelQuery);
response.sendRedirect("register.jsp");
}
if(rs.getInt("logincount")==10)
{
String strdelQuery = "delete * from user where username='"+userName+"' and password='"+password+"'";
int i = st.executeUpdate(strdelQuery);
response.sendRedirect("register.jsp");
}
}
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
%>
For read more information
http://www.roseindia.net/ Thanks