Solved

Function Sequence Error - resultset

Posted on 2004-04-21
7
868 Views
Last Modified: 2012-05-04
Hi
  I'm using VAJ 3.5 with access as backend. In my application I'm getting records from database and displaying it in the JSP. I'm populating my resultset with "Select * from table". In session bean I'm reading records from result set in groups of 10. My first fetch of 10 records works fine. when i do a next for fectching the next set of records I get the following exception java.sql.SQLException: [Microsoft][ODBC Driver Manager] Function sequence error at rs.next().
Could someone tell me whatz wrong.
thanx
vinitha
0
Comment
Question by:rVini
[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
7 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 10876375
You must be not checking if rs.next() return null. And if it does return null, the next call to method will throw an exception
0
 

Author Comment

by:rVini
ID: 10876911
no rs is not null
0
 

Expert Comment

by:tikiliainen
ID: 10877260
Do you use the database connection for anything else in between fetching the two chunks? If you do this then the result set will be pointing to something garbled. You really shoud read in all of the result set into a data structure in one go and close the result set to be 100% sure it is not getting garbled halfway through. To be 99% sure it is not getting garbled through the use of the same connection, go over the code again and ensure you make no calls to the database in between reads or close the result set before you finish reading from it.
0
Independent Software Vendors: 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 30

Expert Comment

by:Mayank S
ID: 10878746
>> rs.next() return null

It will either return true or false, nothing else. And if rs itself is null, it will throw a NullPointerException.

Vinitha,

Could you post some code? Are you, by any chance, scrolling to a wrong position (or doing an extra scroll in a loop)? Make sure you are using your Connection and Statement properly.
0
 

Author Comment

by:rVini
ID: 10880186

I'm including part of my code....hope its more clear

The method populateResultset  is used for populating the result set and its returned to populateGeneric(int iPrevLast, int iNextStart) function.


public java.sql.ResultSet populateResultset(String strTableName, String strFields, String strCondition )
{
      try
      {
            String strQuery;
            java.sql.Connection con = DriverManager.getConnection("jdbc:odbc:DrugDB");
            stmt = con.createStatement();
        
            
            if (strCondition.equalsIgnoreCase("NONE"))
            {
                 strQuery = "Select " + strFields + " from " + strTableName ;
            }
            else
               strQuery = "Select " + strFields + " from " + strTableName + " where " + strCondition;

          ResultSet rs = stmt.executeQuery(strQuery);

            return rs;
       
      }
        catch(Exception e)
        {
                      return null;

        }
        
}






public boolean populateGeneric(int iPrevLast, int iNextStart) {

      // This method populates the values for generic bean
      
      try  
      {

          java.util.Vector vGenericId = new java.util.Vector();
           java.util.Vector vGenericName = new java.util.Vector();

            if (iPrevLast == 0) // populate the result set - first call to session bean    
            {
                   rs =      populateResultset("Generic_master", "*","NONE","Generic_Name");
            }

            
          
            boolean bFlag = rs.next();  // Exception is thrown here
      
// read the resultset
// select only 10 records
//            while (bFlag)
            if (bFlag == true)
            {
            for ( int i = iPrevLast; i < iNextStart ; i++)
            {
                int iGenId = rs.getInt(1);
                Integer Itemp = new Integer(iGenId) ;
                String str = Itemp.toString(iGenId);

                    String strGenName = rs.getString(3);
                vGenericId.addElement(Itemp);
                vGenericName.addElement(strGenName);
                     bFlag = rs.next();
                  if (bFlag == false)
                        i = iNextStart;
                  
            }
            }
            setVGenericId(vGenericId);   //methods in session bean for storing genericid and name
            setVGenericName(vGenericName);
            stmt.close();
            return true;

      }
      catch (Exception eException)
      {
            eException.printStackTrace();
             return false;
      }
   
}


This works fine when i first call the session bean ie populating the resultset and getting the first 10 records. In the next cycle the servlet calls these methods for the next set of 10 (iPrevLast and iNextStart are populated with 10 and 20), and it fails in boolean bFlag = rs.next(); statment. And in between there is no other calls to the resultset.


Servlet code :

if (sview == null)
   {
      Context initial = new InitialContext();  
      Object objref = initial.lookup("ViewPkg/sView");  
      shome = (sViewHome)PortableRemoteObject.narrow(objref,sViewHome.class);
      sview = shome.create();
   }
      
// Call method to get vectors
      boolean bflag =  sview.populateGeneric(iPrevLast,iNextStart);

       vTemp = sview.getVGenericId();  
       vTempGName = sview.getVGenericName();
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 total points
ID: 10886143
For a start, remove: >> stmt.close();

from your populateGeneric () code.

Also, I guess that you have the con declared inside the method and the stmt, rs declared at class level - you should have all at the same level. And after using up your ResultSet, you should close the statement and connection. But for the time being, just see if removing that line helps.
0
 

Author Comment

by:rVini
ID: 10897402
Thanks !! that was the culprit statement, it was closing the resultset. !
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

696 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