Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks but can u give some example of code about that.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, satish

i m using SQL Server as a Database.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to JDBC
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
S Herod
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic