File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to insert date into database?

 
Eman Adenola
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eman Adenola wrote:always a freaking exception

Perhaps it might be helpful to show the exception?
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
leo donahue
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic