1

In the database column1 have date like 2011-03-03 but I want to show only 03-03 and in column2 have string like BHEL.NS but I want to show only BHEL.

<TD><center><%=rs.getString(1)%></center></TD>  
<TD><center><%=rs.getString(2)%></center></TD>

How to do this?

thanks in advance..

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
Siten
  • 4,515
  • 9
  • 39
  • 64

3 Answers3

2

For date you can use SimpleDateFormat and for second column use substring function of String.

Or use substring for both as

rs.getString(1).substring(rs.getString(1).indexOf("-")+1)  
rs.getString(2).substring(0,rs.getString(2).indexOf("."))
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
2

I would recommend you to avoid javacode in view. You can have List of your POJOs fetched and filled up from DB , and then you can render it on view using JSTL

And with your current way you can make it working by following way

<TD><center><%=rs.getString(1).subString(rs.getString(1).indexOf("-")+1)%></center></TD>  
<TD><center><%=rs.getString(2).subString(0,rs.getString(2).indexOf("."))%></center></TD>  

Also See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
2
<TD><center><%=rs.getString(1)!=null?rs.getString(1).subString(rs.getString(1).indexOf("-")+1):"-"%></center></TD>  
<TD><center><%=rs.getString(2)!=null?rs.getString(2).subString(0,rs.getString(2).indexOf(".")):"-"%></center></TD> 
Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46