cancel
Showing results for 
Search instead for 
Did you mean: 

Date format error while accessing date from SQLSERVER

Former Member
0 Kudos

Hi all, in me webdynpro application I have taken Date type for the Input Field.

At date select it is displaying in the format

*2/14/2009 i.e. mm/dd/yyyy*

And when I am saving date in the sql database then the date format changes to..

2009-02-14 i.e..yyyy/mm/dd.

But using the Date format method I have changed the format as per the need to push date in the SQL database table...

In the table SQL the date attribute is in form i.e. 02/14/2009 as like from the date select from the date Input Fieldu2026But the problem is that database is not being able to display in that Input field again.

I have use the coding both at Insertion and selection of the database i.e..

Date Sdate, Edate;

Sdate = Date.valueOf (rs.getString ("Sdate"));

Edate = Date.valueOf (rs.getString ("Edate"));

SimpleDateFormat date Formatter = new SimpleDateFormat ("MM/dd/yyyy");

Sdate = wdContext.currentProjectElement ().getEdate ();

Edate = wdContext.currentProjectElement ().getEdate ();

String Sd = dateFormatter.format (Sdate);

String Ed = dateFormatter.format (Edate);

Date Sdd =Date.valueOf (Sd);

Date Edd =Date.valueOf (Ed);

But at selection of the database the error for the date format isu2026.

java.lang.IllegalArgumentException

If somebody knows how to resolve this ,plz let me know

Regards:

SK

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

thanx

Former Member
0 Kudos

Plz look at the below thread

nikhil_bose
Active Contributor
0 Kudos

for displaying the value only, I think, you are converting to string.

sol1:

1. Create a simple type in dictionary: under Dictionary -> Local Dictionary -> Simple Types

2. go to Definition tab: Change Built-in Type as Date

3. go to Representation tab: specify format e.g.: MM/dd/yyyy

4. go to Context and change the date context attribute to the created type.

sol2:

please try to minimize the casting between Date and String.

I believe in database date is stored as Date type itself. My suggestion will be for displaying keep a separate attribute and set it on each db call.

below code is converting from Date to String.


Date Sdate, Edate;
Sdate = rs.getDate ("Sdate");
Edate = rs.getDate ("Edate");
SimpleDateFormat date Formatter = new SimpleDateFormat ("MM/dd/yyyy");
String Sd = dateFormatter.format (Sdate);
String Ed = dateFormatter.format (Edate);

Former Member
0 Kudos

Hi nikhil thanx for helping..I hav tried both d solutions but problem persist...

Basically in inserting the date in sql server is in date format using Input field and again accessing that date frm the SQL server to display again in that Input field of date format..

wenever i am acessing date frm sql server database table its displaying the error

IllegalFormatException...

Even i tried to display that date value in msg but same error ...

How shud i display the date value frm SQLserver in the same InoutField from were the date has been inserted initially...

nikhil_bose
Active Contributor
0 Kudos

@IllegalFormatException...

make sure that:

1. The datatype bound to the input field is of type : date

2. While retrieving values from ResultSet, result_set.getDate("datecolumn");

3. Database column: datecolumn is of type: date

nikhil