Solved

Function Sequence Error - resultset

Posted on 2004-04-21
7
863 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:mayankeagle
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:
mayankeagle 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 100
topping2 challenge 13 62
Magic Software info 18 105
SUM 2 INTEGER ARRAYS INTO 1 10 63
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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now