Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Date issue

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic