Link to home
Start Free TrialLog in
Avatar of ramoore
ramoore

asked on

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> ");
...                      
Avatar of rrz
rrz
Flag of United States of America image

Just typing mistakes ?  
     eDateColor = "<font color=red>";
       } else {    
  eDateColor = "<font color=black>";
You were missing quotes.  
Avatar of ramoore
ramoore

ASKER

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 {
                                    ^
Avatar of ramoore

ASKER

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.
>if (elapsedDate != null)  && > 120 {
change to
if (elapsedDate != null  && > 120){
Avatar of ramoore

ASKER

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..
Avatar of ramoore

ASKER

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
sorry I was too quick and didn't think.
if (elapsedDate != null  && elapsedDate> 120){
Avatar of ramoore

ASKER

Not yet... new message "operator > cannot be applied to java.lang.String,int"
                      
if (elapsedDate != null  && elapsedDate > 120){
                                                          ^
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ramoore

ASKER

That did it! Thanks a bunch for your help, rrz.
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){
Avatar of ramoore

ASKER

Cool. I'll take your info and do some additional testing on this.. I appreciate your help!!