| Author |
How to insert date into database?
|
Eman Adenola
Greenhorn
Joined: Apr 03, 2011
Posts: 27
|
|
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
Joined: Jan 10, 2002
Posts: 56157
|
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
Eman Adenola wrote:always a freaking exception
Perhaps it might be helpful to show the exception?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Eman Adenola
Greenhorn
Joined: Apr 03, 2011
Posts: 27
|
|
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
Joined: Apr 03, 2011
Posts: 27
|
|
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
Joined: Jan 10, 2002
Posts: 56157
|
|
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
Joined: Apr 03, 2011
Posts: 27
|
|
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
Joined: Jan 10, 2002
Posts: 56157
|
|
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
Joined: Apr 17, 2003
Posts: 327
|
|
|
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.
|
Thanks, leo
|
 |
 |
|
|
subject: How to insert date into database?
|
|
|