This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes date insert autometically in to DB at the time of submitting form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "date insert autometically in to DB at the time of submitting form" Watch "date insert autometically in to DB at the time of submitting form" New topic
Author

date insert autometically in to DB at the time of submitting form

sarika Gupta
Greenhorn

Joined: Apr 27, 2005
Posts: 18
hi,

can someone please help me.my problem is i have no column on the user interface and when i submitt this form the Date is autometically insert into database this Date must be server Date not the client Date bcz client Date may be wrong but server date always right please give an example of code in JAVA that would some how solve my problem.

please help me as soon as possible!!!

thank you!!!
Satish SN
Ranch Hand

Joined: Apr 19, 2005
Posts: 70
Hi Sarika,

U can do the same. Are u calling a servlet/jsp when the form is submitted
in both cases u could call Calendar.getInstance().getTime() which gives u the server date and the same can be used in the insert statement of ur table


Satish SN<br />SCJP 1.4 & SCWCD 1.4
sarika Gupta
Greenhorn

Joined: Apr 27, 2005
Posts: 18
Hi,

Thanks but can u give some example of code about that.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What database are you using?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
sarika Gupta
Greenhorn

Joined: Apr 27, 2005
Posts: 18
Hi, satish

i m using SQL Server as a Database.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I asked because mysql has a timestamp datatype that automatically updates itself when the row is updated.

With SQL-Server, you could write a trigger that does this automatically at the database level, if you so desired.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Moved to JDBC


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

If you want the db to do the date, just call the function that your DB uses to get the current date in your update call ( function for MSSQL is getDate() ):


an update would work the same:

[ April 29, 2005: Message edited by: Jamie Robertson ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Ben Souther:
I asked because mysql has a timestamp datatype that automatically updates itself when the row is updated.


As I haven't worked with mySQL.
Is there any column, of Timestamp datatype, in every table of mySQL? Like we have ROWID in Oracle.
[ April 30, 2005: Message edited by: Adeel Ansari ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

since poster of this thread is using sql server,which already has Datetime datatype for dates and can be used as setTimeStamp() of PreparedStatement or sql server has GETDATE()function to get date in sql


Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
S Herod
Greenhorn

Joined: Apr 25, 2005
Posts: 10
I'd use GETDATE() in the sql, or in oracle SYSDATE (I think mysql uses 'now()')

I wouldn't use a db trigger to insert the date, here's why.

With our current prod db we did use a trigger to update the date to now on insert.

However, we've also had to do a lot of data insertion of old data, and to insert this data and keep the original dates in the old data, you have to turn off the trigger before running the import/insert.

This means a production downtime (because turning off the trigger during normal operation would be bad of course).

In hindsight, we would have stuck with a 'not null' constraint on the date time column and gone with 'sysdate' or the like in the sql.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date insert autometically in to DB at the time of submitting form
 
Similar Threads
One month Extra get added during method call in java.
Storing date in DB using Entity Beans
Servlet and JDBC error
Date in MS SQL Server
for client server programme