Null pointer Exception

Hi experts,
                      I have the following code that displays the attached (snap shot) Table on my jsp page. This code works fine for  most of my backend tables. but today we are going to add another table and I am getting a null pointer exception when I try to run this code, though I am able to generate the table. The last Transactions data is what missing from the output.

       Can someone please help me out with it.
 
       I have attached the jsp output and output from Toad.
<table border="1" cellspacing="1" bgcolor="#FFFFFF" width=99%>
	<tr>
		<th><b>Transactions</b></th>
		<th align='center'><b> Metric </b></th>
		<%  
		        java.util.ArrayList days = dz.getDays();
                for (int i = 0; i < days.size(); i++) {
                %>
		<th align="center"><%=days.get(i)%></th>
		<%
                }
                %>
		<th align="center"><b>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 APM.APM_WEB_SLA_MIN WHERE APPLICATION='EPay'";
 
                        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 EPAY_INSTANCE, SUCCESS_RATE, TOTAL_VOL, NVL(TO_CHAR(d, 'mm/dd/yyyy'), ' ') EVENT_DATE from  APM.APM_WEB_EPAY_METRICPAGE_V, (SELECT TRUNC(SYSDATE - 1) - LEVEL + 1 d FROM DUAL CONNECT BY LEVEL <= 7) WHERE EVENT_DATE(+) = d ORDER BY EPAY_INSTANCE, d";
                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);
                        ArrayList success = new ArrayList();
                        ArrayList volume = 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=2><%=chggrp%></th>
		<td align='center'><b>Volume</b></td>
		<%
                                        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 && rs.getInt(3)==0){
								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)));
 												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 align='center'><b>Success Rate</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>
	<%
                                volume.clear();
                                success.clear();
                                hightlight.clear();
								daycount=0;
                                rowcolor++;
                        }
 
                        conn.close();
                        rs.close();
                        pstmt.close();
 
                } catch (Exception e) {
 
                        e.printStackTrace();
                        conn = null;
 
                }
        %>
 
</table>

Open in new window

EP.PNG
DB-output.PNG
LVL 10
aman0711Asked:
Who is Participating?
 
mrjoltcolaConnect With a Mentor Commented:
Simply set a breakpoint and single step your Java code. Likely the prepare or fetch is failing, and you are catching it with the try{} block, but later down in your page, you are using the "rs" object, assuming it is valid.
0
 
mrjoltcolaConnect With a Mentor Commented:
Correct, I see your try is around the whole page, so my statement wasn't completely accurate.

I would still trace the code in a debugger, or post the stack trace so we can see where it got the NULL exception.
0
 
aman0711Author Commented:
Hi mrjoltcola :)

             Thanks for responding. I guess its with the last application, where I have null data for the column EPAY_INSTANCE
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mrjoltcolaCommented:
Could be, but since we don't have the stack trace, we can only guess for you. Can you provide it?

0
 
aman0711Author Commented:
Hmmm.. Could you tell me how to do that? I can post it within minutes
0
 
mrjoltcolaConnect With a Mentor Commented:
Which JVM / JSP container are you using? It should be in the console log / console / stderr output.

For Tomcat, for example, it would be under apache-tomcat/logs

0
 
aman0711Author Commented:
ohk, Here is the console log:


4/6/09 17:42:01:537 CDT] 00000021 SystemOut     O Connection Details:com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@28de28de
[4/6/09 17:42:04:772 CDT] 00000021 SystemErr     R java.lang.NullPointerException
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm._jsp._Transaction_5F_ep._jspService(_Transaction_5F_ep.java:324)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:85)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:115)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:168)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:92)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
[4/6/09 17:42:04:788 CDT] 00000021 SystemErr     R 	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)

Open in new window

0
 
aman0711Author Commented:
and I am using WAS 6.1
0
 
mrjoltcolaConnect With a Mentor Commented:
I think the prepare or executeQuery is failing.

                        pstmt = conn.prepareStatement(sql);
                        rs = pstmt.executeQuery(sql);

You need to add some debugging log statements (log4j or plain prints to stderr) or trace the code under Eclipse/Netbeans or whichever Java IDE you use.

0
 
aman0711Author Commented:
hmm.. Ok I will try this now
0
 
ManishConnect With a Mentor LeadCommented:
Why not checking null when you are fetching from database?
like
  String key = rs.getString(1);
//check here key is null or not,
   float value = rs.getFloat(2);
//check here float is null or 0.0.
like this..
0
 
aman0711Author Commented:
Thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.