| | |
coversion of dates from java(jsp) to sql
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
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.
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.
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.
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.
![]() |
Other Threads in the JSP Forum
- Previous Thread: Designing a Tree Structure
- Next Thread: help regarding project completion
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web






