coversion of dates from java(jsp) to sql

Reply

Join Date: Jan 2008
Posts: 4
Reputation: rapchak is an unknown quantity at this point 
Solved Threads: 0
rapchak rapchak is offline Offline
Newbie Poster

coversion of dates from java(jsp) to sql

 
0
  #1
Mar 29th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: coversion of dates from java(jsp) to sql

 
0
  #2
Mar 29th, 2008
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 4
Reputation: rapchak is an unknown quantity at this point 
Solved Threads: 0
rapchak rapchak is offline Offline
Newbie Poster

Re: coversion of dates from java(jsp) to sql

 
0
  #3
Mar 29th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: coversion of dates from java(jsp) to sql

 
0
  #4
Mar 30th, 2008
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC