Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:52:52+00:00 2026-06-10T22:52:52+00:00

I have created html table in mail body using below code st = con.createStatement();

  • 0

I have created html table in mail body using below code

            st = con.createStatement();
            rs = st.executeQuery("SELECT nvl(tt.ACTIVITY_NAME,'') as ACTIVITY_NAME, "
                    + " nvl(tt.TL_NAME,'') TL_NAME, "
                    + " nvl(tt.UW_NAME,'') UW_NAME, "
                    + " nvl(tt.TAT_1,'') TAT_1,"
                    + " nvl(tt.TAT_2,'') TAT_2, "
                    + " nvl(tt.TAT_3,'') TAT_3, "
                    + " nvl(tt.TAT_4,'') TAT_4, "
                    + " nvl(tt.TAT_4_PLUS ,'') TAT_4_PLUS, "
                    + " nvl(tt.g_total ,'') AS GRAND_TOTAL "
                    + " FROM uw_activity_tl_uw_tat tt "
                    + " WHERE tt.ACTIVITY_NAME = 'First UW' "
                    + " ORDER BY tt.TL_NAME,tt.UW_NAME");
            StringBuffer sb = new StringBuffer();

            ResultSetMetaData rsmd = rs.getMetaData();
            int numColumns = rsmd.getColumnCount();
            for (int i = 1; i < numColumns + 1; i++) {
                String columnName = rsmd.getColumnName(i);
                sb.append("<th bgcolor=#fcbe07>" + columnName + "</th>");
            }
            ArrayList<String> a = new ArrayList<String>();

            while (rs.next()) {

                a.add(rs.getString(3));

                if (rs.getRow() % 2 == 0) {
                    sb.append("<tr bgcolor=#fcf6cf>");
                    for (int i = 1; i < numColumns + 1; i++) {
                        if (rs.getString(i) == null) {
                            if(i==3)
                            {
                                sb.append("<td bgcolor=#fcbe07><b>"+ " "+ "</b></td>");

                            }


                        } else {

                            if (i == 6 || i == 7 || i == 8)
                                sb.append("<td><FONT COLOR=#ff0000>"
                                        + rs.getString(i) + "</FONT></td>");
                            else if(i==3 && (rs.getString(3).equalsIgnoreCase("") || rs.getString(3)==null)){
                                sb.append("<td bgcolor=#fcbe07><b>"+ rs.getString(i) + "</b></td>");
                            }else{
                                sb.append("<td>" + rs.getString(i) + "</td>");
                            }
                        }
                    }

                    sb.append("</tr>");
                } else {

                    sb.append("<tr>");
                    for (int i = 1; i < numColumns + 1; i++) {
                        if (rs.getString(i) == null) {
                            if(i==3)
                            {
                                sb.append("<td bgcolor=#fcbe07><b>"+ " " + "</b></td>");

                            }

                        } else {
                            if (i == 6 || i == 7 || i == 8)
                                sb.append("<td><FONT COLOR=#ff0000>"
                                        + rs.getString(i) + "</FONT></td>");
                            else if(i==3 && (rs.getString(3).equalsIgnoreCase("") || rs.getString(3)==null)){
                                sb.append("<td bgcolor=#fcbe07><b>"+ rs.getString(i) + "</b></td>");
                            }else{
                                sb.append("<td>" + rs.getString(i) + "</td>");
                            }
                        }
                    }

                    sb.append("</tr>");

                }

            }

            String html = "<html>" + message.getSubject()
                    + "</title></head><body><table border=\"1\">"
                    + sb.toString() + "</table></body></html>";
            message.setContent(html, "text/html");

In the image only one cell is highlighted and I want to highlight the entire row which has any empty cell.Please guide. My query is how to highlight the entire row if any cell is empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:52:54+00:00Added an answer on June 10, 2026 at 10:52 pm

    Short answer: Move the check for the third column and change the <tr> line.

    Truthfully, the code you have is a bit of a mess. Personally, I would make the following changes that will make maintence so much easier:

    1. Switch to using classes instead of hard coding bgcolors and so forth.
    2. Set up your system to return associative arrays instead of numeric arrays. That will make reading the code after a lot easier.
    3. Set up intermediate variables to hold the values returned. Do any and all of your calculations and settings things there. THEN dump the entire table-row in one go. That separates your “functional” code from your “display code.”

    However, in a pinch, something like this will get you going:

    tmp = rs.getString(3);
    if (tmp == null) {
      sb.append("<tr bgcolor=#ffffff>");
    } else {
      sb.append("<tr bgcolor=#fcf6cf>");
    }
    

    BTW – the HTML you generate isn’t valid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created HTML TABLE from JSON data of PHP using JQuery. After creating
I have the following code which creates a new table. var html = '<table>';
I have created a simple layout using the HTML div tag. I would like
I have created web pages where am using pixel to position various html elements.
I have created my entire website by using a main table, and having the
I have a mysql table. I have created a html table and filled it
i have created an sql job for sending mails daily.. i am using HTML
I have a web page that I created with html tags(form and table) and
I have to filter a html-table. To do so I created an each callback
I have dynamically created HTML table clicking on its TH will reload the table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.