• 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

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic