• 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

PreparedStatement/update query

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friends,

I have prob with update Query..

1)

PreparedStatement ps=conn.prepareStatement("UPDATE tablename SET exitdate=?,exittime=? WHERE mobileno=?");

ps.setString(1,dateOfEntry);
ps.setString(2,timeOfEntry);
ps.setLong(3,mobileno);

2)

PreparedStatement ps=conn.prepareStatement("UPDATE tablename SET exitdate=? WHERE mobileno=?");

ps.setString(1,dateOfEntry);
ps.setLong(2,mobileno);


the (1) not executing wid no error.
(2) works fine ..confuse with this behaviour..

I have MySqlSERVER 5.0
and JSP 1.2

please help me.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to be using Strings for Date values. Why are you not using a date data type?
[ January 17, 2007: Message edited by: Paul Sturrock ]
 
ashirvad jain
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does it make any differences?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theoritically your statement should work fine.. (upto my knowledge) I mean I have worked on much more complicated statements.

If an error doesn't occur my guess is that you didn't properly initialize the fields you're pa.. if anythings wrong with the database or your sql syntax an SQLException should occur.. make sure you catch all of'em.

You better also use a java.sql.Date object instead of a string to set up the date. If you have a String represantation of the date creating a date object is really easy. check out the doc. otherwise you can get a string from the calendar class. There has been a few topics around check them out..
 
Malith Yapa
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theoritically your statement should work fine.. (upto my knowledge) I mean I have worked on much more complicated statements.

If an error doesn't occur my guess is that you didn't properly initialize the fields you're pa.. if anythings wrong with the database or your sql syntax an SQLException should occur.. make sure you catch all of'em.

You better also use a java.sql.Date object instead of a string to set up the date. If you have a String representation of the date creating a date object is really easy. check out the doc. otherwise you can get a string from the calendar class. There has been a few topics around check them out..
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ashirvad jain:
does it make any differences?



Yes:
  • From a database point of view you weaken your data constraints by using a character data type. The field might be called "date" but you can insert "yuyiuyu" as a valid date.
  • It removes the need to ensure the formatting of the date remains consistant between the application and the database.

  • reply
      Bookmark Topic Watch Topic
    • New Topic