Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

error while inserting date into oracle table from jsf page  RSS feed

 
Vav Priya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im trying to take date from a jsf form and put it into database table using hibernate. whatever date i enter the month is always stored as Jan. i get correct values for year and day.this is my xhtml and java code

addevent.xhtml :


EventBean.java


i gave 2015-08-06 from the form .when i tried to print eventDate , it shows Sat Jan 03 05:36:00 IST 2015
why does this happen? how do i resolve this?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your eventDate is a "Date" object then it will display as "Sat Jan 03 05:36:00 IST 2015"

The best approach in my opinion with dates anyway is keep it as Strings so your sql does not need to do any conversion whatsoever. As long as your format is correct (yyyy-mm-dd) then you would be set.

Make sure you do validation on the server side too.
 
Vav Priya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:If your eventDate is a "Date" object then it will display as "Sat Jan 03 05:36:00 IST 2015"

The best approach in my opinion with dates anyway is keep it as Strings so your sql does not need to do any conversion whatsoever. As long as your format is correct (yyyy-mm-dd) then you would be set.

Make sure you do validation on the server side too.


when i use String for date i get the error :
ORA-01861: literal does not match format string
i'm really confused.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the sql looks like just before insert?
 
Vav Priya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:So what's the sql looks like just before insert?


i changed both the formats(in java class and sql table) to yyyy-mm-dd and still getting the same error. i tried converting the data type of date in the sql table to varchar and it is working fine.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not an answer to the question, and that's not a good solution. Now your table can contain any value, and your code must parse these values into dates.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!