my appln.is;
to register new users and deleting after a particular time (say 30 days).
can anyone modify the code and point out the mistakes i did.
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class LoginServlet extends HttpServlet
{
private Connection c = null;
private Statement s = null;
private ResultSet rs = null;
public void init(ServletConfig sc) throws ServletException
{
super.init(sc);
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
c=DriverManager.getConnection("jdbc:oracle:oci8:@ospltest","developer","developer");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void doPost(HttpServletRequest req,HttpServletResponse
res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
HttpSession hs = req.getSession(true);
String login = req.getParameter("login");
String pass = req.getParameter("pass");
StringBuffer p = new StringBuffer(toLowerCase("login"));
String logname = new String(p);
hs.putValue(user,"login");
try
{
s = c.createStatement();
rs = s.executeQuery("select password,opendate from
logintable where logname='"+logname+"')");
rs.next();
String name = rs.getString(1);
String opendate = rs.getString(2);
Date date1
java.util.date.toString(opendate);--------------------------//since
opendate is in string format we convert it into date type.
if(name.equals(pass))
{
java.util.Date date2=new
java.util.Date();------------------//used to get todays date.
//String mydate=date2.toLocaleString();
if(date2-date1
<=30)---------------------------------//if date of register and todays date is more than 30 days.his a/c must be expired.
{ is this correct.
<html><body>
u r valid usr.
</ body></ html>
}
else
{
n=s.executeUpdate("delete from logintable where
logname='"+logname+"'");
<html>
<body>
<b>u r time is expired.
thank u for being with us.
</b>
</ body></ html>
}
}
else
{
<html><body>
<b>invalid password. enter correctly.
<a href= login.html>back</a>
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void destroy()
{
try
{
c.close();
s.close();
}
catch(Exception e)
{
}
}
table used:
logintable
----------
logname varchar2(25) PRIMARY KEY
password varchar2(25) not null
opendate date
bye
vinod.