• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating timestamp field

 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Im creating a reporting servlet which shows the values of the row for a certain username and then lets user make changes to it and updates it. If a user sets the timestamp field to blank in the form and hits 'update' button, it updates it to some random date and time instead of showing it blank. This is wut my code looks like in dopost()just to show blank if the users sets it to blank.
String m = req.getParameter("initialized");
if (m == null || m.equals(""))
member.initialized = null;
member.update();
in my Member class, i have this code in the update method:
String m ="";
if(initialized == null)
m = null;
update = "UPDATE vippas SET initialized = \"" + m + "\"";.
Im totally stuck here..Could any1 please tell me wut the problem is and suggest a solution. Thanks for your help.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You SQL will translate to :

UPDATE vippas SET initialized = "null";

That probably won't make sense to a column of type DATETIME or TIMESTAMP.
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what should i do???..cos i have run out of solutions???.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What i was trying to point out was that you are quoting the java null value with double quotes.

So when it gets to the database, this is no longer SQL NULL, it is a string with the letters 'n', 'u', 'l' and 'l'.
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Mike,
I understood wut u meant and solved it..I'm sorry i couldn't post a reply earlier and you had to reply again. Thanks for your help...appreciate it..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!