Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issue converting from oracle.jbo.domain.Date to java.util.Calendar and oracle.jbo.domain.Timestamp b

JDeveloper Newbie (11.1.1.6.0)Dec 26 2013 — edited Dec 27 2013

Hi everyone,

Working with dates has been more difficult than I thought! Please take a look at the code; everything compiles, but it fails because I am not casting correctly. Any help would be appreciated.

Here are the imports:

import java.sql.SQLException;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import oracle.jbo.domain.Date;

import oracle.jbo.domain.Timestamp;

Here is the method:

    public static Date nextDay(String sDate, int day,

                              String simpleDateFormat) {

        Date result = null;

        java.util.Date date;

        if (sDate != null) {

            try {

                System.out.println("try...");

                Calendar calendar = Calendar.getInstance();

                SimpleDateFormat dateFormat =

                    new SimpleDateFormat(simpleDateFormat);

                calendar.setTime(dateFormat.parse(sDate));

                calendar.set(Calendar.DAY_OF_WEEK, day); // day = Calendar.SUNDAY

                calendar.set(Calendar.HOUR_OF_DAY, 0);

                calendar.set(Calendar.MINUTE, 0);

                calendar.set(Calendar.SECOND, 0);

                calendar.add(Calendar.DATE, 7);

                dateFormat.format(calendar.getTime());

                try {

                    System.out.println("try (inner)...");

                    System.out.println("new Timestamp(calendar.getTime().getTime())): " +

                                      new Timestamp(calendar.getTime().getTime()));

                    result = new Date(new Timestamp(calendar.getTime().getTime())); // Code fails here.

                    return result;

                } catch (SQLException e) {

                    System.out.println("catch (SQLException e)...");

                    e.printStackTrace();

                }

                return null;

            } catch (ParseException e) {

                System.out.println("catch (ParseException e)...");

                e.printStackTrace();

            }

            return null;

        }

        return null;

    }

Here is the output:

try...

try (inner)...

new Timestamp(calendar.getTime().getTime())): 2013-12-29 00:00:00.0

catch (SQLException e)...

java.sql.SQLException: Initialization failed

  at oracle.sql.DATE.<init>(DATE.java:237)

  at oracle.jbo.domain.Date.<init>(Date.java:378)

James

This post has been answered by vinaykumar2 on Dec 27 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2014
Added on Dec 26 2013
3 comments
9,037 views