Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Null pointer Exception

Posted on 2009-04-06
12
Medium Priority
?
643 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:aman0711
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 1600 total points
ID: 24082195
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
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 1600 total points
ID: 24082213
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
 
LVL 10

Author Comment

by:aman0711
ID: 24082238
Hi mrjoltcola :)

             Thanks for responding. I guess its with the last application, where I have null data for the column EPAY_INSTANCE
0
Industry Leaders: 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!

 
LVL 40

Expert Comment

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

0
 
LVL 10

Author Comment

by:aman0711
ID: 24082319
Hmmm.. Could you tell me how to do that? I can post it within minutes
0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 1600 total points
ID: 24082431
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
 
LVL 10

Author Comment

by:aman0711
ID: 24082452
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
 
LVL 10

Author Comment

by:aman0711
ID: 24082456
and I am using WAS 6.1
0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 1600 total points
ID: 24082833
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
 
LVL 10

Author Comment

by:aman0711
ID: 24082847
hmm.. Ok I will try this now
0
 
LVL 11

Assisted Solution

by:Manish
Manish earned 400 total points
ID: 24084517
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
 
LVL 10

Author Closing Comment

by:aman0711
ID: 31567267
Thanks :)
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question