ProgressBar with database
Hi Friends,
Please help me out
In my project ,
1) I am selecting Employee ID from the database
2) While loop is used to get more information about employee using
these Employee ID.
3) ProgressBar is used to show progress of while loop ie. how many
employess ID are still remaining
Problem :
ProgressBar directly show 100% when all records fetch from the
database
Thanks in advanced.
[461 byte] By [
jay.Da] at [2007-10-3 5:25:47]

Thanks for replying me.
Code is big. Hence sending only main code.
........................
........................
/*Creating object of ProgressBar */
progressbar = new JProgressBar();
progressbar.setBorderPainted(true);
progressbar.setValue(0);
.....................
.....................
try{
while(itr_b.hasNext()){
String batch= (String)itr_b.next();
String sql = " (SELECT DISTINCT OPCODE FROM TBL_"+batch+"_SET1_DE1 GROUP BY opcode "+
" UNION " +
" SELECT DISTINCT OPCODE FROM TBL_"+batch+"_SET2_DE1 GROUP BY opcode) "+
" UNION " +
" (SELECT DISTINCT OPCODE FROM TBL_"+batch+"_SET1_DE2 GROUP BY opcode "+
" UNION "+
" SELECT DISTINCT OPCODE FROM TBL_"+batch+"_SET2_DE2 GROUP BY opcode) " +
" UNION "+
" (SELECT DISTINCT OPCODE FROM TBL_"+batch+"_SET1_DE3 GROUP BY opcode"+
" UNION "+
" SELECT DISTINCT OPCODE FROM TBL_"+batch+"_SET2_DE3 GROUP BY opcode)"+
" UNION "+
" (SELECT DISTINCT SQCOPCODE FROM "+"TBL_"+batch+"_SET1_DE3 "+
" UNION "+
" SELECT DISTINCT SQCOPCODE FROM "+"TBL_"+batch+"_SET2_DE3 "+" Group by SQCOPCODE)" ;
Statement stmt = connection.createStatement() ;
ResultSet rs=stmt.executeQuery(sql);
/* Adding opcode into TreeSet */
while(rs.next()){
String op = rs.getString(1);
if(!op.equals("Y0000"))
opcode.add(op);
} // while rs.next()
} // while union
} catch(SQLException e){
e.printStackTrace();}
int cnt1=0;
Iterator itr_op = opcode.iterator();
while(itr_op.hasNext()){
String opcode_name =(String) itr_op.next();
cnt1= progressbar.getValue();
progressbar.setValue(cnt1++);
progressbar.paintImmediately(20,0,450,32);
.........................
.........................
}// End of while loop
progressbar.setValue(100);
.........................
.........................
Message was edited by:
jay.D
Message was edited by:
jay.D
jay.Da at 2007-7-14 23:33:00 >

Here is the simple code that works ProgressBar. It simply ticks the progressbar and thats the thing u were not able to do.
-
import javax.swing.*;
import java.awt.*;
public class ProgressBarDemo extends JFrame implements Runnable
{
JProgressBar bar;
Thread thread; //Using Thread
public ProgressBarDemo()
{
super("Testing ProgressBar");
Container c=getContentPane();
c.setLayout(new FlowLayout());
bar=new JProgressBar();
c.add(bar);
setSize(400,300);
setVisible(true);
bar.setBorderPainted(true);
bar.setValue(10);
bar.paintImmediately(20,5,5,5);
thread=new Thread(this);
thread.start();
}
public void run()
{
try
{
for(int i=0;;i++)
{
bar.setValue(i);
thread.sleep(10);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new ProgressBarDemo();
}
}