JSP/Java: NullPointerException with scrollable result set

Posted on 2005-03-10
Medium Priority
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:

      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???
Question by:go4java
LVL 35

Expert Comment

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


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...


Author Comment

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?

Author Comment

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);
                hitsHistory = rs_hist.getInt("treffer");
                sHits = Integer.toString(hitsHistory);

...in addition, there is another result set, called rs_browse - that shouldn't give any problem??!
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 35

Expert Comment

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...

LVL 19

Expert Comment

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.

Author Comment

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.
LVL 35

Accepted Solution

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

                PreparedStatement ps = null ;
                ResultSet prs = null ;
                    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() ;
                    try { if( prs != null ) prs.close() ; } catch( SQLException ex ) {}
                    try { if( ps != null ) ps.close() ; } catch( SQLException ex ) {}

Expert Comment

ID: 37859534
thanks  Kuldeepchaturvedi

Featured Post

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!

Question has a verified solution.

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

Before you approach an Ionic Mobile App development company for developing mobile apps using the ionic framework, you must know why you should choose the framework. Let's try to understand that through this article.
These seven tips can help you create an extraordinary website, one that captivates audiences and has them wanting to return regularly for more. Keep reading to find out what your site is missing and what you need to add!
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…

615 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