User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 401,999 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,519 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 672 | Replies: 3
Reply
Join Date: Jan 2008
Posts: 4
Reputation: rapchak is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rapchak rapchak is offline Offline
Newbie Poster

coversion of dates from java(jsp) to sql

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,695
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Jan 2008
Posts: 4
Reputation: rapchak is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rapchak rapchak is offline Offline
Newbie Poster

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

  #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  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,695
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 8:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC