• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Updating timestamp field

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic