tags:

views:

104

answers:

3

Hi all, I am working with web Dynpro java.. I have created a stateless session bean wherin 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(). Bt for showRecords() i am not able to fetch the dates..

This is the follwing 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 anybodey please help.. Thanks Ankita

A: 

hi Ankita,

Can you describe the TABLE COLUMN which holds the dates ?

Also, after you read the resultSet, what is the value of the start date and "end date" ?

anjanb
A: 

Ankita,

Which DB are you using ?

anjanb
+1  A: 

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

kolrie