Link to home
Start Free TrialLog in
Avatar of rVini
rVini

asked on

Function Sequence Error - resultset

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
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

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
Avatar of rVini
rVini

ASKER

no rs is not null
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.
Avatar of Mayank S
>> 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.
Avatar of rVini

ASKER


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();
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rVini

ASKER

Thanks !! that was the culprit statement, it was closing the resultset. !