hi everyone. I am doing a project in jsp where i need to check the duration of logins of a particular client. If the client doesnot login for 6 months(say) his account should expire. For this purpose i am taking system date and storing it in sql database. I have problems in converting a java.util.date to java.sql.date. I need to update the system date(from jsp code) everytime the user logs in, to sql database. For this purpose i am using simple Update statement.

Data type in sql is Date. and datatype in jsp is SimpleDateFormat(yyyy-MM-dd).(i need only yyyy-MM-dd format)

SimpleDateFormat abc = new SimpleDateFormat( "yyyy.MM.dd" );
Date now= new Date();
dbst.executeUpdate("update dates set date2 = '"+(dont know what to give)+"' where username ='xyz'");

I am using 2 date columns one for getting latest date and the other for old date. then i can find out the date difference. I must also compare the dates before updating them to database. For this purpose i must compare the already existing dates with current user(from jsp) date.

Friends please help me in converting the dates. Thanx in advance.

8 Years
Discussion Span
Last Post by jwenting

you shouldn't do this in a JSP, therefore no help is needed.

And why the HELL are you not using a PreparedStatement for your database operation?
Your current style is slow, error prone, highly database dependent, and highly vulnerable to SQL injection attacks.


I am new to jsp. so still i am in learning stage.
I donno much about prepared statement. i know the usage of prepared statement just for inserting the values but not for updating the values. so i am trying to do with update statement. So any help is appreciated.


PreparedStatement works the same way for whatever SQL statement you employ it.
And if you're just getting started, best to get started doing things the right way instead of the wrong way which you are doing.
Java code in JSP went out of vogue nearly a decade ago, use JSTL instead and put all the Java code in Servlets and their associated classes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.