0

I am working with web Dynpro java.. I have created a stateless session bean wherein I have created business methods for inserting and retrieving records from my dictionary table. My table has two fields of java.sql.Date type The web service that i have created is working fine for insertRecords(), but for showRecords() I am not able to fetch the dates..

This is the following code I have applied..

public WrapperClass[] showRecords() 
{
    ArrayList arr = new ArrayList();

            WrapperClass model;

            WrapperClass[] modelArr = null;

            try {
                InitialContext ctx = new InitialContext();
                DataSource ds = (DataSource)ctx.lookup("jdbc/SAPSR3DB");
                Connection conn = ds.getConnection();

                PreparedStatement stmt = conn.prepareStatement("select * from TMP_DIC");

                ResultSet rs = stmt.executeQuery();

                while(rs.next())
                {
                     model  = new WrapperClass();

                    model.setTitle(rs.getString("TITLE"));
                    model.setStatus(rs.getString("STATUS"));
                    model.setSt_date(rs.getDate("START_DATE"));
                    model.setEnd_date(rs.getDate("END_DATE"));

                    arr.add(model);
                    //arr.add(rs.getString(2));
                    //arr.add(rs.getString(3));
                }
                modelArr = new WrapperClass[arr.size()];
                for(int j=0;j<arr.size();j++)
                {

                    model = (WrapperClass)arr.get(j);
                    modelArr[j] = model;
                }
                stmt.close();
                conn.close();
            } catch (NamingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            arr.toArray(modelArr);
            return modelArr;
}

Can anybody please help.. Thanks Ankita

Durandal
  • 5,575
  • 5
  • 35
  • 49

2 Answers2

2

Did you try getTimestamp() instead of getDate()? What is the error you get when you attempt to get it as a date?

kolrie
  • 12,562
  • 14
  • 64
  • 98
0

I use another approach.

I create in addition to the bean, also the services, where I create functions that contains the query to manipulate the DB tables.

Now, in the Java Wb Dynpro I put something like this:

try {
            ctx = new InitialContext();

            Object o = ctx
                    .lookup("sc.fiat.com/um~pers_app/LOCAL/UserServices/com.fiat.sc.um.pers.services.UserServicesLocal");
            userServices = (UserServicesLocal) o;

} catch (Exception e) {
            logger.traceThrowableT(Severity.ERROR, e.getMessage(), e);
            msgMgr.reportException(e);
        }

in the wdDoInit method. I also declare like this

private UserServicesLocal userServices;

the object.

Now I will able to manipulate my DB tables calling methods of the services classes...

sharkbait
  • 2,980
  • 16
  • 51
  • 89