?
Solved

JSP/Java: NullPointerException with scrollable result set

Posted on 2005-03-10
8
Medium Priority
?
852 Views
Last Modified: 2012-04-18
I've a JSP (list.jsp) with 2k lines of code.
Looping through a result set 'rs_bowse' with index 'i', I always get the following error:

java.lang.NullPointerException
      at oracle.jdbc.driver.ScrollableResultSet.findColumn(ScrollableResultSet.java:914)
      at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1374)
      at org.apache.jsp.list$jsp._jspService(list$jsp.java:3048)
...

--> line 3048 --> rs_browse.absolute(i);

i = 1...n
rs_browse = null? When debugging, rs_browse <> null.

How to find the place/reason why rs_bowse should be null???
0
Comment
Question by:go4java
[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
8 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13506563
Hmmm...line 3048 scares me a little, but can you post a bit of your JSP code?

Questions:

1)  Are you setting it to null (stupid question, but the most likely reason) -- check in your exception handlers, finally blocks, etc...
2)  Are you closing the underlying Statement before you access the resultset?  Closing the statement (in most JDBC implementations) closes the resultset too...

Tim
0
 

Author Comment

by:go4java
ID: 13506900
Thank you, TimYates.
Could I send you a screenshot (JPEG) of the rs_browse detail inspection (output by IntelliJ IDEA)?
If so, E-Mail?
0
 

Author Comment

by:go4java
ID: 13507773
Is it possible to have multiple result sets running in ONE single JSP?

The following additional code gives the problem:

sql_hist = "select count(mandt) as treffer from sapr3.ZPRIDESTATHIST v " +
                                       "where v.mandt = '" + sMandt +
                                       "' and v.sales_division = '" + sSalesDivision + "'" +
                                       " and v.register_number = '" + sRegisterNo + "'";
                rs_hist = stmt_hist.executeQuery(sql_hist);
                rs_hist.next();
                hitsHistory = rs_hist.getInt("treffer");
                sHits = Integer.toString(hitsHistory);
                rs_hist.close();

...in addition, there is another result set, called rs_browse - that shouldn't give any problem??!
0
Technology Partners: 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 35

Expert Comment

by:TimYates
ID: 13508165
AFAIK, it really depends on the JDBC implementation...

Personally, I try not to have more than one statement/resultset/connection going at the same time...

ie:  for each connection, I declare a single statement, and a single resultset...

if I need data from one resultset with data from another, I read the data out into an ArrayList, then close the original ResultSet and Statement, and make another one...

Tim
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13509909
Some times having more than one result set on the same statement runs in to trouble.. ( it usually messes the first result set that you would have obtained from the statement). Try creating another statement for your rs_browse and see if it fixes the problem for you.
0
 

Author Comment

by:go4java
ID: 13514417
Hi Tim,

this is what I did:
- executing query
- get data
- close result-set

So, no idea from where the nullpointer comes from. Without the code snippet mentioned above, the script runs smoothly.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 1500 total points
ID: 13514766
try replacing that snippet with:

                PreparedStatement ps = null ;
                ResultSet prs = null ;
                try
                {
                    sql_hist = "select count(mandt) as treffer from sapr3.ZPRIDESTATHIST v where v.mandt = ? and v.sales_division = ? and v.register_number = ?" ;
                    ps = connection.prepareStatement( sql_hist ) ;
                    ps.setString( 1, sMandt ) ;
                    ps.setString( 2, sSalesDivision ) ;
                    ps.setString( 3, sRegisterNo ) ;
                    prs = ps.executeQuery();
                    if( rs_hist.next() )
                    {
                        hitsHistory = prs.getInt( "treffer" );
                        sHits = Integer.toString(hitsHistory);
                    }
                }
                catch( SQLException ex )
                {
                    ex.printStackTrace() ;
                }
                finally
                {
                    try { if( prs != null ) prs.close() ; } catch( SQLException ex ) {}
                    try { if( ps != null ) ps.close() ; } catch( SQLException ex ) {}
                }
 
0
 

Expert Comment

by:hasegawa2012
ID: 37859534
thanks  Kuldeepchaturvedi
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Summer 2017 Scholarship Winners have been announced!
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

752 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