• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Display table data in color if meets criteria, JSP

I am getting information from an Oracle database and displaying this data back to a customer's browser using JSP.
In the code snippet, I am calculating the "number of days" from when an item was submitted.
This number is an alias called "Elapsed".

I would like to display the number of the elapsed days as a color, only if it meets the criteria I have shown
below. This works fine, if I use only the != null statement and omit the >= calculation, but not the way have it.
Can someone help me get this working? Thanks!

...
//grab the data and do the math
ResultSet rs = stmt.executeQuery("SELECT ROUND(SYSDATE-SUBMIT_DATE)AS Elapsed FROM MYTABLE");

String elapsedDate = rs.getString("Elapsed");
String eDateColor;

//If elapsed date is greater than 120 days, then display the number in red
if (elapsedDate != null) && > 120 {
      eDateColor = <font color=red>;
        } else {      
  eDateColor = <font color=black>;
 }
 
out.println(" <td><center>" + eDateColor + elapsedDate + "</font></center></td> ");
...                      
0
ramoore
Asked:
ramoore
  • 7
  • 5
1 Solution
 
rrzCommented:
Just typing mistakes ?  
     eDateColor = "<font color=red>";
       } else {    
  eDateColor = "<font color=black>";
You were missing quotes.  
0
 
ramooreAuthor Commented:
Thanks for the comment! Yes, I did forget the quotes, but I am getting a message
"illegal start of expression" which is pointing to the "&&" in the statement. This has to do with my problem somehow.

 if (elapsedDate != null)  && > 120 {
                                    ^
0
 
ramooreAuthor Commented:
I think my SQL statement in my resultset does not see the output as a "numeral" or something... so the > 120 is hick-uping on this... don't know.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rrzCommented:
>if (elapsedDate != null)  && > 120 {
change to
if (elapsedDate != null  && > 120){
0
 
ramooreAuthor Commented:
That didn't do it either, I get the same "... illegal start of..." message, but now pointing to the ">" sign..

if (elapsedDate != null  && > 120) {
                                       ^

and if I do something like this, I get a different message...
"operator > cannot be applied to java.lang.String,int"
...
if (elapsedDate > 120) {
                      ^

am trying some different things..
0
 
ramooreAuthor Commented:
I have some data that works out to be "7" for the elapsed number of days. So if I do something like this. that entry shows up in the red color....

if ((elapsedDate != null) && elapsedDate.equals("7")) {

I just can't get ">=" to work
0
 
rrzCommented:
sorry I was too quick and didn't think.
if (elapsedDate != null  && elapsedDate> 120){
0
 
ramooreAuthor Commented:
Not yet... new message "operator > cannot be applied to java.lang.String,int"
                      
if (elapsedDate != null  && elapsedDate > 120){
                                                          ^
0
 
rrzCommented:
Sorry I didn't look closly enough at your code.  
if (elapsedDate != null  && Integer.parseInt(elapsedDate) > 120){
0
 
ramooreAuthor Commented:
That did it! Thanks a bunch for your help, rrz.
0
 
rrzCommented:
Great, thanks for the points. But if you have trouble with that later then you might have to  use something like  
int intElapsed = 0;
try {
                      intElapsed = Integer.parseInt(elapsedDate);
} catch (NumberFormatException nfe) {
                      intElapsed = 0;  // or whatever default you want to use
}
if (intElapsed > 120){
0
 
ramooreAuthor Commented:
Cool. I'll take your info and do some additional testing on this.. I appreciate your help!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now