Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

about array length

please see the ???part, thanks first

boolean max_flag = false;
for(int p=0; max_flag == false; p++)
{
IObject[] unuseful = ImporterObjectManager.getUnusefulObjects("Tom",5000,p);
                                    
int sizee = unuseful .length; //?????????????????? I think sizee should always be 5000, but I got 5000,10000,7566,2566,0??what is wrong??????or I am wrong?
System.out.println(String.valueOf(sizee));
if(sizee== 0)
{
System.out.println(String.valueOf(sizee));
max_flag = true;
}
}

in other java file:

public static IObject[] getUnusefulObjects(String name, int record_per_page, int page)
      {                                         
            Connection conn            = null;
            PreparedStatement statement      = null;
            ResultSet resultset            = null;
            ArrayList <IObject> list      = new ArrayList<IObject>();
            
            String sql            = "SELECT * FROM my_table WHERE name = %s LIMIT %s, %s ";
            String[] args      = { name,
                        String.valueOf(record_per_page * page),
                        String.valueOf(record_per_page * (page+1)),
                          };
            
            sql= String.format(sql, args[0],args[1], args[2]);
            
            try
            {
                  conn      = ConnectionPool.getConnection(true);
                  statement      = conn.prepareStatement(sql);
                  
                  resultset      = statement.executeQuery();
                  
                  while (resultset.next())
                  {
                        int id= resultset.getInt(1);
                        
                        IObject obj      = new IObject(new Integer(id)); //coded in other java file
                        list.add(obj);
                  }
                  
                  return getObjectsFromList(list);  ////coded in other java file
            }
            catch (Exception e)
            {
                  writeErrorEmail(e);
            }
            finally
            {
                  Utilities.closeDBConnections(resultset, statement, conn);
            }
      
            return null;
      }
      

0
keepworking
Asked:
keepworking
  • 3
1 Solution
 
objectsCommented:
looks like it should be as many rows are returned by the query
though depends what getObjectsFromList(list); does
0
 
objectsCommented:
          String.valueOf(record_per_page * page),
                    String.valueOf(record_per_page * (page+1)),

you multiple records_per_page (5000) by the page number
0
 
objectsCommented:
should be more like:

           String.valueOf(record_per_page * page),
                    String.valueOf(record_per_page),
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now