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

handling NULL data on front end

Hello Experts,
                     I am trying to output the following table on my jsp page (Snap shot Attached). if put and eye on the second last row of the table i.e. ORBIT... thr success is 0.00%. and on the backend its NULL.
                     I want to convert these zeros to 100% with the attached code.
<%!public ArrayList getDays() {
 
                ArrayList dateList = new ArrayList();
                DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
 
                Calendar cal = Calendar.getInstance();
                dateFormat.format(cal.getTime());
 
                for (int i = 0; i <= 6; i++) {
                        cal.add(Calendar.DATE, -1);
                        dateList.add(dateFormat.format(cal.getTime()));
 
                }
                return dateList;
        }%> <%!public ArrayList padZeros(ArrayList a, int count, int value) {
                for (int i = 0; i < count; i++)
                        a.add(new Integer(value));
                return a;
        }%> <%
        java.util.ArrayList days = getDays();
        java.util.Collections.reverse(days);
 %>
<h5><b>Results as of <%=df.format(prevDay.getTime())%></b></h5>
<table border="1" cellspacing="1" bgcolor="#FFFFFF" WIDTH=99%>
	<tr>
		<th><b>Transactions</b></th>
		<th><b> Metric </b></th>
		<%
                for (int i = 0; i < days.size(); i++) {
                %>
		<th><%=days.get(i)%></th>
		<%
                }
                %>
		<th><b>Minimum SLA </b></th>
	</tr>
	<%
                Connection conn = null;
                conn = db.getConnection();
 
                String sql = "";
                PreparedStatement pstmt = null;
                ResultSet rs = null;
 
                try {
 
                        ///////// NEW /////////
                        // CHANNELGROUP to SLAMIN lookup table
                        Hashtable slaMinList = new Hashtable();
                        sql = "SELECT METRIC, SLA_MIN FROM VSLAND.APM_WEB_SLA_MIN WHERE APPLICATION='Kana Connect C'";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        while (rs.next()) {
                                String key = rs.getString(1);
                                float value = rs.getFloat(2);
                                slaMinList.put(key, new Float(value));
                        }
                        rs.close();
                        pstmt.close();
                        ///////// NEW /////////
 
                        sql = "SELECT CAMPAIGN_GROUP, SUCCESS_RATE, TOTAL_VOL, BOUNCE_RATE, NVL(TO_CHAR(d, 'mm/dd/yyyy'), ' ') EVENT_DATE from  VSLAND.APM_KANAC_C_90D_V, (SELECT TRUNC(SYSDATE - 1) - LEVEL + 1 d FROM DUAL CONNECT BY LEVEL <= 7) WHERE EVENT_DATE(+) = d ORDER BY CAMPAIGN_GROUP, d";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        ArrayList success = new ArrayList();
                        ArrayList volume = new ArrayList();
                        ArrayList bounce = new ArrayList();
                        ArrayList hightlight = new ArrayList();
                        float min = 0;
                        String chggrp = "";
                        if (rs.next()) {
                                chggrp = rs.getString(1);
                        }
                        boolean loop = true;
                        int rowcolor = 0; /// color code
						int daycount =0; //index for dates.
                        while (loop) {
                                boolean innerloop = true;
        %>
	<%
        if (rowcolor % 2 == 0) {
        %>
	<tr>
		<%
                } else {
                %>
	
	<tr style='background-color:#D0CECE'>
		<%
                }
                %>
 
		<th rowspan=3><%=chggrp%></th>
		<td><b>Volume</b></td>
		<%
                                        java.text.DecimalFormat nf = new java.text.DecimalFormat(
                                        "#0.00");
                                        java.text.DecimalFormat nv = new java.text.DecimalFormat(
                                        "##,##,###");
                                        java.text.DecimalFormat np = new java.text.DecimalFormat(
                                        "#0.00%");
      
                                        while (innerloop) {
									String thisDate = rs.getString("EVENT_DATE");//get the record date								
                                while(!thisDate.equals(days.get(daycount)))
								{      //My dates dont match so we must be missing data, insert zeros
								success.add(new Float(1.0));
 
                                volume.add(new Integer(0));
			                                           	//also increase the day by one here
                                  daycount++;
                                  
				
								}
								float f = rs.getFloat(2);
 
                                ///////// NEW /////////
                                //                               if (f < 87)
                                Object ftemp = slaMinList.get(chggrp);
 
                                if (null != ftemp) {
                                        min = ((Float) ftemp).floatValue();
                                } else {
                                        min = 111;
                                }
 
                                if (f < min && min != 111)
                                        ///////// NEW /////////
                                        hightlight.add(new Integer(1)); // true
                                else
                                        hightlight.add(new Integer(0)); // false
                                success.add(new Float(f));
 
                                volume.add(new Integer(rs.getInt(3)));
                                float b = rs.getFloat(4);
		                   		bounce.add(new Float(b));
 												daycount++;
                                if (!rs.next()) {
                                        innerloop = false;
                                        loop = false;
                                        break;
                                }
                                if (!rs.getString(1).equals(chggrp))
                                        innerloop = false;
                                chggrp = rs.getString(1);
                                        }
 
                                        success = padZeros(success, 7 - success.size(),1);
                                        hightlight = padZeros(hightlight, 7 - hightlight.size(),0);
                                        volume = padZeros(volume, 7 - volume.size(),0);
                                        for (int v = 0; v < volume.size(); v++) {
 
                                out.print("<td align='center'>" + nv.format(volume.get(v)) + "</td>");
                                        }
 
                                        ///////// NEW /////////
                                        out.print("<td align='center'>NA</td>");
                                        ///////// NEW /////////
                %>
	</tr>
	<%
        if (rowcolor % 2 == 0) { /// color code
        %>
	<tr>
 
		<%
                } else {
                %>
	
	<tr style='background-color:#D0CECE'>
		<%
                }
                %>
		<td><b>Sucess</b></td>
 
		<%
                                for (int s = 0; s < success.size(); s++) {
                                int h = ((Integer) hightlight.get(s)).intValue();
                                if (h == 1)
                                        ///////// NEW /////////
                                        //                                        out.print("<td style='background-color:#E33740'>"
                                        out.print("<td align='center' style='background-color:#FF0000'>"
                                        ///////// NEW /////////
 
                                        + np.format(success.get(s))
                                        + "</span></td>");
                                else
                                        out.print("<td align='center'>" + np.format(success.get(s))
                                        + "</td>");
                                        }
                                        if (min != 111) {
                                out.print("<td align='center'>" + np.format(min) + "</td>");
                                        } else {
                                out.print("<td align='center'>NA</td>");
                                        }
                %>
	</tr>
	<%
	if (rowcolor % 2 == 0) { /// color code
	%>
	<tr>
		<%
		} else {
		%>
	
	<tr style='background-color:#D0CECE'>
		<%
		}
		%>
 
		<td>Bounce Rate</td>
		<%
				for (int b = 0; b < bounce.size(); b++) {
				out.print("<td align='center'>" + np.format(bounce.get(b)) + "</td>");
					}
		%>
		<td>&nbsp;</td>
	</tr>
 
 
 
 
 
 
	<%
                                volume.clear();
                                success.clear();
                                bounce.clear();
                                hightlight.clear();
								daycount=0;
                                rowcolor++;
                        }
 
                        conn.close();
                        rs.close();
                        pstmt.close();
 
                } catch (Exception e) {
 
                        e.printStackTrace();
                        conn = null;
 
                }
        %>
 
</table>

Open in new window

KN.JPG
0
aman0711
Asked:
aman0711
  • 15
  • 11
5 Solutions
 
KuldeepchaturvediCommented:
float f = rs.getFloat(2);
 if(f==0.00)
  f=1.0;

That should do it..

Only issue with the above code is that if F is actually 0.0 in the datbase and not NULL, it will still be displayed as 100%. I am not sure if its okay or not.

0
 
aman0711Author Commented:
Hmmm.... for some applications Success rate is 100%.
and yesterdays problem sir that u fixed in the padding method.. is it because of this:

success.add(new Float(1.0));

volume.add(new Integer(0));
//also increase the day by one here
daycount++;


}
float f = rs.getFloat(2);
We are again fetching values after the while loop is closed?
0
 
KuldeepchaturvediCommented:
>Hmmm.... for some applications Success rate is 100%.

that will come as 100 as will happen in any case..

and no your explanation for yday's problem is still not cirrect..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
aman0711Author Commented:
ok I will again go through with that code, until I find the problem :)
Sir, I started with making a common class for paddin zeros and DateList.
Gettting an error on the line:
java.util.Collections.reverse(days);
as
variabledeclaratorid expected after this token

package com.apm;
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
 
public class DateZeroPad {
	
	
	  public ArrayList getDays() {
		  
		  ArrayList DateList = new ArrayList();
		  DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
		  
		  Calendar cal = Calendar.getInstance();
		  dateFormat.format(cal.getTime());
		  
		  for(int i = 0; i <= 6; i++){
			  cal.add(Calendar.DATE, -1);
			  DateList.add(dateFormat.format(cal.getTime()));
						  
		  }
		  		  
		return DateList;
		
	      }
	  
	  java.util.ArrayList days = getDays();
	  java.util.Collections.reverse(days);
	      
	   public ArrayList PadZeros(ArrayList a, int count) { 
	    	
	    	for(int i=0; i < count; i++ )
	    		a.add(new Integer(0));
	    	  	
	    	return a;
	    	
	    }
	    
	    
	    
	  
	}

Open in new window

0
 
KuldeepchaturvediCommented:
you are not closing your method and not returning the days object back..


0
 
aman0711Author Commented:
I am sorry sir, Please bear with me.
The two methods, getDays and padZeros are closed.
The same code works for jsp, why not in this class?
 
0
 
KuldeepchaturvediCommented:
See below
public ArrayList getDays() { //start of method getDays
		  
		  ArrayList DateList = new ArrayList();
		  DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
		  
		  Calendar cal = Calendar.getInstance();
		  dateFormat.format(cal.getTime());
		  
		  for(int i = 0; i <= 6; i++){
			  cal.add(Calendar.DATE, -1);
			  DateList.add(dateFormat.format(cal.getTime()));
						  
		  }
		  		  
		return DateList; //return the object from the method
		
	      }// close of method getdays
	  
	  java.util.ArrayList days = getDays(); // what method does this code belong to?
	  java.util.Collections.reverse(days); // what method does this code belong to?
	     // These two lines belong nowehere.! they are not inside any methods and hence wont work 
	   public ArrayList PadZeros(ArrayList a, int count) { /start of another method here
	    	

Open in new window

0
 
aman0711Author Commented:
cool.. Placed those two lines inside the first method and its fixed. i dont need to put in any return statement, right Sir?
Please bear with me, I can only ask you all these stupid questions. :)
Sir now I will make a smaple page, with this code in classes. will ask u more
0
 
KuldeepchaturvediCommented:
you do need to make a return statement, otherwise it wont work ( it will compile but wont work)..

ideally speaking your first method shd like following. That is all you need..

public ArrayList getDays() { //start of method getDays
             
              ArrayList DateList = new ArrayList();
              DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
             
              Calendar cal = Calendar.getInstance();
              dateFormat.format(cal.getTime());
             
              for(int i = 0; i <= 6; i++){
                    cal.add(Calendar.DATE, -1);
                    DateList.add(dateFormat.format(cal.getTime()));
                                     
              }
            java.util.Collections.reverse(DateList);                
            return DateList; //return the object from the method
            
            }// close of method getdays
0
 
aman0711Author Commented:
Thank  You Sir.
Changed that..
Sir can you please guide me a bit. how to make use of these methods in my jsp page.
make use of usebean.
then?

<h2>Kana Connect C Transactions</h2>
<%!public ArrayList getDays() {
 
                ArrayList dateList = new ArrayList();
                DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
 
                Calendar cal = Calendar.getInstance();
                dateFormat.format(cal.getTime());
 
                for (int i = 0; i <= 6; i++) {
                        cal.add(Calendar.DATE, -1);
                        dateList.add(dateFormat.format(cal.getTime()));
 
                }
                return dateList;
        }%> <%!public ArrayList padZeros(ArrayList a, int count, int value) {
                for (int i = 0; i < count; i++)
                        a.add(new Integer(value));
                return a;
        }%> <%
        java.util.ArrayList days = getDays();
        java.util.Collections.reverse(days);
 %>
 
<h5><b>Results as of <%=df.format(prevDay.getTime())%></b></h5>
<table border="1" cellspacing="1" bgcolor="#FFFFFF" WIDTH=99%>
	<tr>
		<th><b>Transactions</b></th>
		<th><b> Metric </b></th>
		<%
		               
                for (int i = 0; i < days.size(); i++) {
                %>
		<th><%=days.get(i)%></th>
		<%
                }
                %>
		<th><b>Minimum SLA </b></th>
	</tr>
	<%
                Connection conn = null;
                conn = db.getConnection();
 
                String sql = "";
                PreparedStatement pstmt = null;
                ResultSet rs = null;
 
                try {
 
                        ///////// NEW /////////
                        // CHANNELGROUP to SLAMIN lookup table
                        Hashtable slaMinList = new Hashtable();
                        sql = "SELECT METRIC, SLA_MIN FROM VSLAND.APM_WEB_SLA_MIN WHERE APPLICATION='Kana Connect C'";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        while (rs.next()) {
                                String key = rs.getString(1);
                                float value = rs.getFloat(2);
                                slaMinList.put(key, new Float(value));
                        }
                        rs.close();
                        pstmt.close();
                        ///////// NEW /////////
 
                        sql = "SELECT CAMPAIGN_GROUP, SUCCESS_RATE, TOTAL_VOL, BOUNCE_RATE, NVL(TO_CHAR(d, 'mm/dd/yyyy'), ' ') EVENT_DATE from  VSLAND.APM_KANAC_C_90D_V, (SELECT TRUNC(SYSDATE - 1) - LEVEL + 1 d FROM DUAL CONNECT BY LEVEL <= 7) WHERE EVENT_DATE(+) = d ORDER BY CAMPAIGN_GROUP, d";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        ArrayList success = new ArrayList();
                        ArrayList volume = new ArrayList();
                        ArrayList bounce = new ArrayList();
                        ArrayList hightlight = new ArrayList();
                        float min = 0;
                        String chggrp = "";
                        if (rs.next()) {
                                chggrp = rs.getString(1);
                        }
                        boolean loop = true;
                        int rowcolor = 0; /// color code
						int daycount =0; //index for dates.
                        while (loop) {
                                boolean innerloop = true;
        %>
	<%
        if (rowcolor % 2 == 0) {
        %>
	<tr>
		<%
                } else {
                %>
	
	<tr style='background-color:#D0CECE'>
		<%
                }
                %>
 
		<th rowspan=3><%=chggrp%></th>
		<td><b>Volume</b></td>
		<%
                                        java.text.DecimalFormat nf = new java.text.DecimalFormat(
                                        "#0.00");
                                        java.text.DecimalFormat nv = new java.text.DecimalFormat(
                                        "##,##,###");
                                        java.text.DecimalFormat np = new java.text.DecimalFormat(
                                        "#0.00%");
      
                                        while (innerloop) {
									String thisDate = rs.getString("EVENT_DATE");//get the record date								
                                while(!thisDate.equals(days.get(daycount)))
								{      //My dates dont match so we must be missing data, insert zeros
								success.add(new Float(1.0));
 
                                volume.add(new Integer(0));
			                                           	//also increase the day by one here
                                  daycount++;
                                  
				
								}
								float f = rs.getFloat(2);
								if (f==0.00){
								f=1;
								}
 
                                ///////// NEW /////////
                                //                               if (f < 87)
                                Object ftemp = slaMinList.get(chggrp);
 
                                if (null != ftemp) {
                                        min = ((Float) ftemp).floatValue();
                                } else {
                                        min = 111;
                                }
 
                                if (f < min && min != 111)
                                        ///////// NEW /////////
                                        hightlight.add(new Integer(1)); // true
                                else
                                        hightlight.add(new Integer(0)); // false
                                success.add(new Float(f));
 
                                volume.add(new Integer(rs.getInt(3)));
                                float b = rs.getFloat(4);
		                   		bounce.add(new Float(b));
 												daycount++;
                                if (!rs.next()) {
                                        innerloop = false;
                                        loop = false;
                                        break;
                                }
                                if (!rs.getString(1).equals(chggrp))
                                        innerloop = false;
                                chggrp = rs.getString(1);
                                        }
 
                                        success = padZeros(success, 7 - success.size(),1);
                                        hightlight = padZeros(hightlight, 7 - hightlight.size(),0);
                                        volume = padZeros(volume, 7 - volume.size(),0);
                                        for (int v = 0; v < volume.size(); v++) {
 
                                out.print("<td align='center'>" + nv.format(volume.get(v)) + "</td>");
                                        }
 
                                        ///////// NEW /////////
                                        out.print("<td align='center'>NA</td>");
                                        ///////// NEW /////////
                %>
	</tr>
	<%
        if (rowcolor % 2 == 0) { /// color code
        %>
	<tr>
 
		<%
                } else {
                %>
	
	<tr style='background-color:#D0CECE'>
		<%
                }
                %>
		<td><b>Sucess</b></td>
 
		<%
                                for (int s = 0; s < success.size(); s++) {
                                int h = ((Integer) hightlight.get(s)).intValue();
                                if (h == 1)
                                        ///////// NEW /////////
                                        //                                        out.print("<td style='background-color:#E33740'>"
                                        out.print("<td align='center' style='background-color:#FF0000'>"
                                        ///////// NEW /////////
 
                                        + np.format(success.get(s))
                                        + "</span></td>");
                                else
                                        out.print("<td align='center'>" + np.format(success.get(s))
                                        + "</td>");
                                        }
                                        if (min != 111) {
                                out.print("<td align='center'>" + np.format(min) + "</td>");
                                        } else {
                                out.print("<td align='center'>NA</td>");
                                        }
                %>
	</tr>
	<%
	if (rowcolor % 2 == 0) { /// color code
	%>
	<tr>
		<%
		} else {
		%>
	
	<tr style='background-color:#D0CECE'>
		<%
		}
		%>
 
		<td>Bounce Rate</td>
		<%
				for (int b = 0; b < bounce.size(); b++) {
				out.print("<td align='center'>" + np.format(bounce.get(b)) + "</td>");
					}
		%>
		<td>&nbsp;</td>
	</tr>
 
 
 
 
 
 
	<%
                                volume.clear();
                                success.clear();
                                bounce.clear();
                                hightlight.clear();
								daycount=0;
                                rowcolor++;
                        }
 
                        conn.close();
                        rs.close();
                        pstmt.close();
 
                } catch (Exception e) {
 
                        e.printStackTrace();
                        conn = null;
 
                }
        %>
 
</table>

Open in new window

0
 
aman0711Author Commented:
Sir,
       yesterdays problem:
Is it because of the clear method we are using on our ArrayLists?
0
 
KuldeepchaturvediCommented:
then just use it..

assume your called your bean "myBean"..

then all you need to do is

java.util.ArrayList days = myBean.getDays(); //note you have already used the 'revese' in method itself, no need to do it again..


and

success = myBean.padZeros(success, 7 - success.size(),1);
                                        hightlight = myBean.padZeros(hightlight, 7 - hightlight.size(),0);
                                        volume = myBean.padZeros(volume, 7 - volume.size(),0);
                                     

And remove the methods from the page..( the top part of your code above)
0
 
aman0711Author Commented:
Hello Sir,
      I did this and worked perfectly. What else I can move to this code, out of the jsp page.
and I still didnt get the error , why 0.00 was getting populated (which u corrected by editing padZeros method)

<%@ page contentType="text/html; charset=iso-8859-1" language="java"
	errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page
	import="java.text.DateFormat,java.text.SimpleDateFormat,java.util.*,java.sql.*"%>
<jsp:useBean class="com.apm.DBConn" id="db"></jsp:useBean>
<jsp:useBean class="com.apm.DateZeroPad" id="dz"></jsp:useBean>
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
<title>Transactions</title>
<style type="text/css">
        @import url("../styles/intranet.css");             /* main stylesheet */
        @import url("../styles/intranet-2col.css");        /* column stylesheet */
        @import url("../styles/intranet-2col-1024.css");   /* 1024px stylesheet */
     /* @import url("styles/intranet-green.css"); */   /* sample accent color stylesheet */
  </style>
 
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<%
	SimpleDateFormat df = new SimpleDateFormat("EEE - MMM d, yyyy");
	Calendar origDay = Calendar.getInstance();
	Calendar prevDay = (Calendar) origDay.clone();
	prevDay.add(Calendar.DAY_OF_YEAR, -1);
%>
 
<div id="page-wrapper"><%@include file="header.jsp"%>
<div id="column-wrapper"><!-- begin columns --> <%@include
	file="left-panel.jsp"%>
 
<div id="content"><!-- begin content column -->
<div class="inner">
 
<h2>Transactions</h2>
    
 
<h5><b>Results as of <%=df.format(prevDay.getTime())%></b></h5>
<table border="1" cellspacing="1" bgcolor="#FFFFFF" WIDTH=99%>
	<tr>
		<th><b>Transactions</b></th>
		<th><b> Metric </b></th>
		<%
		        java.util.ArrayList days = dz.getDays();               
                for (int i = 0; i < days.size(); i++) {
                %>
		<th><%=days.get(i)%></th>
		<%
                }
                %>
		<th><b>Minimum SLA </b></th>
	</tr>
	<%
                Connection conn = null;
                conn = db.getConnection();
 
                String sql = "";
                PreparedStatement pstmt = null;
                ResultSet rs = null;
 
                try {
 
                        ///////// NEW /////////
                        // CHANNELGROUP to SLAMIN lookup table
                        Hashtable slaMinList = new Hashtable();
                        sql = "SELECT METRIC, SLA_MIN FROM VSLAND.APM_WEB_SLA_MIN WHERE APPLICATION='Kana Connect C'";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        while (rs.next()) {
                                String key = rs.getString(1);
                                float value = rs.getFloat(2);
                                slaMinList.put(key, new Float(value));
                        }
                        rs.close();
                        pstmt.close();
                        ///////// NEW /////////
 
                        sql = "SELECT CAMPAIGN_GROUP, SUCCESS_RATE, TOTAL_VOL, BOUNCE_RATE, NVL(TO_CHAR(d, 'mm/dd/yyyy'), ' ') EVENT_DATE from  VSLAND.APM_KANAC_C_90D_V, (SELECT TRUNC(SYSDATE - 1) - LEVEL + 1 d FROM DUAL CONNECT BY LEVEL <= 7) WHERE EVENT_DATE(+) = d ORDER BY CAMPAIGN_GROUP, d";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        ArrayList success = new ArrayList();
                        ArrayList volume = new ArrayList();
                        ArrayList bounce = new ArrayList();
                        ArrayList hightlight = new ArrayList();
                        float min = 0;
                        String chggrp = "";
                        if (rs.next()) {
                                chggrp = rs.getString(1);
                        }
                        boolean loop = true;
                        int rowcolor = 0; /// color code
						int daycount =0; //index for dates.
                        while (loop) {
                                boolean innerloop = true;
        %>
	<%
        if (rowcolor % 2 == 0) {
        %>
	<tr>
		<%
                } else {
                %>
	
	<tr style='background-color:#D0CECE'>
		<%
                }
                %>
 
		<th rowspan=3><%=chggrp%></th>
		<td><b>Volume</b></td>
		<%
                                        java.text.DecimalFormat nf = new java.text.DecimalFormat(
                                        "#0.00");
                                        java.text.DecimalFormat nv = new java.text.DecimalFormat(
                                        "##,##,###");
                                        java.text.DecimalFormat np = new java.text.DecimalFormat(
                                        "#0.00%");
      
                                        while (innerloop) {
									String thisDate = rs.getString("EVENT_DATE");//get the record date								
                                while(!thisDate.equals(days.get(daycount)))
								{      //My dates dont match so we must be missing data, insert zeros
								success.add(new Float(1.0));
 
                                volume.add(new Integer(0));
			                                           	//also increase the day by one here
                                  daycount++;
                                  
				
								}
								float f = rs.getFloat(2);
								if (f==0.00){
								f=1;
								}
 
                                ///////// NEW /////////
                                //                               if (f < 87)
                                Object ftemp = slaMinList.get(chggrp);
 
                                if (null != ftemp) {
                                        min = ((Float) ftemp).floatValue();
                                } else {
                                        min = 111;
                                }
 
                                if (f < min && min != 111)
                                        ///////// NEW /////////
                                        hightlight.add(new Integer(1)); // true
                                else
                                        hightlight.add(new Integer(0)); // false
                                success.add(new Float(f));
 
                                volume.add(new Integer(rs.getInt(3)));
                                float b = rs.getFloat(4);
		                   		bounce.add(new Float(b));
 												daycount++;
                                if (!rs.next()) {
                                        innerloop = false;
                                        loop = false;
                                        break;
                                }
                                if (!rs.getString(1).equals(chggrp))
                                        innerloop = false;
                                chggrp = rs.getString(1);
                                        }
 
                                        success = dz.PadZeros(success, 7 - success.size(),1);
                                        hightlight = dz.PadZeros(hightlight, 7 - hightlight.size(),0);
                                        volume = dz.PadZeros(volume, 7 - volume.size(),0);
                                        for (int v = 0; v < volume.size(); v++) {
 
                                out.print("<td align='center'>" + nv.format(volume.get(v)) + "</td>");
                                        }
 
                                        ///////// NEW /////////
                                        out.print("<td align='center'>NA</td>");
                                        ///////// NEW /////////
                %>
	</tr>
	<%
        if (rowcolor % 2 == 0) { /// color code
        %>
	<tr>
 
		<%
                } else {
                %>
	
	<tr style='background-color:#D0CECE'>
		<%
                }
                %>
		<td><b>Sucess</b></td>
 
		<%
                                for (int s = 0; s < success.size(); s++) {
                                int h = ((Integer) hightlight.get(s)).intValue();
                                if (h == 1)
                                        ///////// NEW /////////
                                        //                                        out.print("<td style='background-color:#E33740'>"
                                        out.print("<td align='center' style='background-color:#FF0000'>"
                                        ///////// NEW /////////
 
                                        + np.format(success.get(s))
                                        + "</span></td>");
                                else
                                        out.print("<td align='center'>" + np.format(success.get(s))
                                        + "</td>");
                                        }
                                        if (min != 111) {
                                out.print("<td align='center'>" + np.format(min) + "</td>");
                                        } else {
                                out.print("<td align='center'>NA</td>");
                                        }
                %>
	</tr>
	<%
	if (rowcolor % 2 == 0) { /// color code
	%>
	<tr>
		<%
		} else {
		%>
	
	<tr style='background-color:#D0CECE'>
		<%
		}
		%>
 
		<td>Bounce Rate</td>
		<%
				for (int b = 0; b < bounce.size(); b++) {
				out.print("<td align='center'>" + np.format(bounce.get(b)) + "</td>");
					}
		%>
		<td>&nbsp;</td>
	</tr>
 
	<%
                                volume.clear();
                                success.clear();
                                bounce.clear();
                                hightlight.clear();
								daycount=0;
                                rowcolor++;
                        }
 
                        conn.close();
                        rs.close();
                        pstmt.close();
 
                } catch (Exception e) {
 
                        e.printStackTrace();
                        conn = null;
 
                }
        %>
 
</table>
 
<p class="reverse"></p>
 
<p><small></small></p>
 
<!-- end content column, then column wrapper --></div>
</div>
<%@include file="footer.jsp"%></div>
</div>
 
</body>
</html>

Open in new window

0
 
KuldeepchaturvediCommented:
now it is a better jsp. & I will not be telling you the problem with that jsp.
0
 
aman0711Author Commented:
lol... ok :)
I will try on that again :(
0
 
aman0711Author Commented:
Sir, give me some vague hint.
Is it because of the while loops?
The padding code is in the inner loop?
Its just taking a zero instead of 1.0
0
 
KuldeepchaturvediCommented:
its a combination of how data is arranged, the inner loop and the logic to complete the loop.
0
 
aman0711Author Commented:
Hmmm.. Ok.. will concentrate on that
0
 
aman0711Author Commented:
Hmm.. Sir is it because our padding zeros method is outsite the loop and the code inside the innerloop where we are inserting values 1.0 and 0 is over -riding the paddnig code? :(
0
 
KuldeepchaturvediCommented:
nowhere close..

one more hint..

the original code would be working in every case but in cases where the data is missing from middle to the end date.
if will always work if the data is available for the end date but not available for middle dates..
0
 
aman0711Author Commented:
Hmmm.. ok. :(
0
 
aman0711Author Commented:
Sir,
is it because of this statement:

while(!thisDate.equals(days.get(daycount)))
Because we comparing the date and then breaking it right thr?
0
 
KuldeepchaturvediCommented:
Its because of

if (!rs.getString(1).equals(chggrp))
                                        innerloop = false;
                                chggrp = rs.getString(1);


assume you have dates from 2/10 to 2/16..

you have data for channel A - 2/10 to 2/16
Channel B - 2/10 to 2/14 only
Channel C - 2/10 to 2/16
First channel will work fine..
second chaneel will fill data for 2/10 - 2/14..
when we try to compare the 2/15..
your channel value will change to C ( because that is what the next row in the database is)..

now that the channel name has changed..

if (!rs.getString(1).equals(chggrp))
                                        innerloop = false;
                                chggrp = rs.getString(1);

this code will break the loop and will reset the daycounter to zero ( i.e. 2/14).. leaving 2/15 and 2/16 unfilled for channel B..
now at the end of the processing
PadZeros will see that success is filled up only till 2/14, it will call PadZero and will fill 2/15 and 2/16 with zeros ( instead of 1.0).


0
 
aman0711Author Commented:
oh k., Honestly, I would never guessed it.  I thought a lot.. but this never came into my mind..
       so the way you edit the padZeros method is best solution to this Sir?
0
 
KuldeepchaturvediCommented:
yes..!
0
 
aman0711Author Commented:
ohk.. Thank you Sir :)
 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 15
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now