Solved

Function Sequence Error - resultset

Posted on 2004-04-21
7
866 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

828 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