• 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

How to insert date into database?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
before I go on...
Now I feel a little better..for the past hour I've been trying to insert a freaking date into the database...a date for crying out loud..
my lecturer stored it as a string...when i convert it into a string to debug i display and it displays fine....to insert it..always a freaking exception

I changed the format to Date/Time in the database..and still no freaking luck..aaargh


So I'm hoping the jsp gods in this forum can help me out here...how can I solve this problem?
How to insert a date into a database?

Btw i am using Access..and I have no choice..i gotta use it..
any help appreciated thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does inserting a date into a database have to do with JSP? I'll move this along to the JDBC forum, where I'm sure you'll get asked for more details.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eman Adenola wrote:always a freaking exception


Perhaps it might be helpful to show the exception?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dates and SQL can be a nightmare at time (which format does the server require? month-date-year? day-month-year? will year-month-date always work?), so I always use a PreparedStatement with its setTime, setDate and setTimestamp methods.
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey thanks for replying..
@Bear I am trying to use JSTL and JSP..that's why I thought it would be in that forum...sorry.


One of many attempts

The format is dd-mm-yyyy

@Rob I will google that PreparedStatement and see if I can resolve the problem thanks.
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mmn...I think I resolved the problem now..
I used the same code I had..but it appears that one of the fields is a primary key...as a result inserting the same primary twice into database throws the exception.I
It's ridiculous..I would have thought a simple error to suffice...I think I can make my way from here now..if not i'll be back ha ha

Thanks fellas.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eman Adenola wrote:
@Bear I am trying to use JSTL and JSP..


Yikes! You're using the JSTL SQL tags for real code? Even the JSTL Spec says that those tags are for toy code only. I'd refactor to move the database access to a model layer as soon as possible.
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
eh..yeah i thought that was what <sql:update> was for?
And this is only how far.and if this isn't real code..then I am screwed then lol..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a properly structured web application, database access is handled in the model layer, completely sequestered away from the user interface. You may want to look up the concept of MVC and "Model 2".

Perhaps this article can get you started.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With regards as to the format the database requires, just issue a select date() query, or your database equivalent, and you'll have the format you need to insert.
 
reply
    Bookmark Topic Watch Topic
  • New Topic