Time taken for a method to run. ?

I have a query regarding ascertaining the time taken

for a method to execute

I have a SQL statement that I reads 10,000 rows.

String a_SQL ="Select.....from TableA";

try{

IQuery query = m_UC.createQuery();

SimpleTableModel stm = query.executeSelect(a_SQL);

}catch(SQLException se){

}

// Query Over.

privatevoid displayJTable(){

// display rows read from the query above.

}

As the query is executing,I want to display a progress bar

showing the status of the query.

Now I cant use this :

start = System.currentTimeMillis();

try{

IQuery query = m_UC.createQuery();

SimpleTableModel stm = query.executeSelect(a_SQL);

}catch(SQLException se){

}

end = System.currentTimeMillis();

System.out.println(" Time taken to display " + (end - start)/1000);

The above will give me the time elapsed in seconds for the SQL query to execute,but

this is not what I want.

What i want is to use this :

// Progress BAR executing,so I need to get to know the time

// taken for the query to run

try{

the SQL execution

}cach(){

}

// Query over.

// Stop Progres Bar.

// Display JTable.

How can I know when to stop the Progress Bar as I have no handle

on the time taken to execute the query?

Any help will be appreciated

[2320 byte] By [bhuru_luthriaa] at [2007-10-2 5:52:05]
# 1
You can't. there is no way to make the progress bar magically foresee how long operation x will take.
CeciNEstPasUnProgrammeura at 2007-7-16 2:01:45 > top of Java-index,Java Essentials,Java Programming...
# 2
So what do u suggest I do to display the Progress Bar and once the SQL execution is completed,then stop showing the Progress Barand display the JTable
bhuru_luthriaa at 2007-7-16 2:01:45 > top of Java-index,Java Essentials,Java Programming...
# 3

You can have a separate thread (or maybe it's just part of the regular GUI update thread? I don't know details about GUIs) that puts up an hourglass or spinning clock hands or dancing hamster or whatever to indicate that something is going on, but like the man says, you can't know ahead of time how long it will take to run a query, so you can't show percent done. You also don't in general know ahead of time how many rows will be returned so that doesn't help you.

You might be able to do something for the processing of the returned data, once the query completes, because then you can often get a count of the number of rows, so you process each row in a loop, and update the % done counter each time through the loop.

targaryena at 2007-7-16 2:01:45 > top of Java-index,Java Essentials,Java Programming...
# 4
> So what do u suggest I do to display the Progress Bar> and once the SQL execution is completed,then stop> showing the Progress Bar> and display the JTableThe progress bar has something like an idle loop. Display that.
CeciNEstPasUnProgrammeura at 2007-7-16 2:01:45 > top of Java-index,Java Essentials,Java Programming...
# 5
> > The progress bar has something like an idle loop.> Display that.@OP: This is done by calling:progressBar.setIndeterminate(true);
happy_hippoa at 2007-7-16 2:01:45 > top of Java-index,Java Essentials,Java Programming...