Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrive data from db2 as month and year wise

 
saswat rashmi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone and good morning

i have problem ,
in my jsp page there is option for month and year .in the month drop down list of month it coming and in year drop down list of year it s coming .

now i have to get the data from db2 based on selection of month and year .but in db2 the data is stored as int he form of YYYY/MM/DD

i dont how to write the code for this in jsp .please help .please some example how to write the code for this
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saswat,
If you have a date/calendar object, you can call get(Calendar.MONTH) and get(Calendar.YEAR) to get these fields. If your value is stored in a date/time field in db2, you can use resultSet.getDate() to get a Date object right away.

If it really is stored as a char/varchar in the format "YYYY/MM/DD", you will need to call SimpleDateFormat to create a date first.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should also mention that it is considered poor practice to have code - especially JDBC code - in a JSP. Better to put it in a Java class or servlet. This makes the code easier to debug and maintain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic