Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Date issue

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

I have Java Bean(POJO).

which contains the property name maturtyDate of type java.util.Date.

I am using struts framework so from view the value of form fields will be automatically set by framework.

but i am getting below exception when i submit the form.


stacktrace



Even if i dont pass any value from UI for property maturityDate i am getting the same exception and if i remove the textbox for maturityDate from UI form gets submitted without any exception.

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

Use java.sql.Date OR String as data type for maturityDate property. just for your information... the date pattern for MySQL is yyyy/mm/dd. So, after validation convert it in the required format OR accepts is in the same format. Otherwise you may get another SQLException!
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
will java.sql.Date work ?

I tried java.sql.Date but its giving me the same error illegal argument exception.

i think it will try to do the below, or will it cast to java.sql.Date ?



 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jigar Naik wrote:will java.sql.Date work ?

I tried java.sql.Date but its giving me the same error illegal argument exception.

i think it will try to do the below, or will it cast to java.sql.Date ?





I think if the variable is declared as String, then also it works.
I have used such varibles which are dates and I have declared them as strings.
SQL server has many formats to store dates.You have convert method in SQL Server to convert the date to any format you want.
Information on convert method is available on internet
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String will always work because request.getParameter("") will always return String.
 
Mai Vala
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jigar Naik wrote:String will always work because request.getParameter("") will always return String.



Yes it does work....then what is your problem.
You want to use only the Date Datatype?
There is a difference in the formats java.util.Date and java.sql.Date...
so it's better if you take it as String.....rather taking it Date datatype and converting.
 
Rahul Nair
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jigar Naik wrote:String will always work because request.getParameter("") will always return String.



Yes, it works for string, However it will gives you SQLException when you execute the SQL query if you have mentioned date data type for maturityDate in Table. The IllegalArgumentException is occoures because you are casting the "" (empty string) in Date type. So, for that as i mentioned earlier you need to validate the html input fields before submission.
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic