1

I want to show a progress bar dialog box of my application importing to database from a csv file, using a while loop -

Here is my code -

try
               {
                BufferedReader br=new BufferedReader(new FileReader("temp.csv"));
                String line;
                line=br.readLine();
                while((line=br.readLine())!=null)
                {
                    String[]value = line.split(",");

                    String sql = "INSERT into main ([Ticket #], Status, Priority, Department, [Account Name]) "
                     + "values ('"+value[0]+"','"+value[1]+"','"+value[2]+"','"+value[3]+"','"+value[4]+"')";

                    System.out.println(sql);

                    PreparedStatement pst = null;

                    try{
                        pst = db.prepareStatement(sql);
                        pst.executeUpdate();

                    }finally{
                        if(pst != null){
                            pst.close();
                        }
                    }

                }
                br.close();


               }

               catch(Exception e)
               {
                JOptionPane.showMessageDialog(null, e);
               }

            }

I want a progress of my while loop in execution.

satnam
  • 1,457
  • 4
  • 23
  • 43
  • so what have you tried? Also is the reading of `readLine()` twice a bug? – Scary Wombat Mar 12 '14 at 08:07
  • Thing is if you want an accurate progress bar you'll have to count the number of lines in the CSV beforehand otherwise you cannot know many lines will 100% mark take. – Ceiling Gecko Mar 12 '14 at 08:08
  • After you know how many lines there are in the CSV it's only a matter of creating a dialog box via the graphical library of your choice and increment it's value in respect to the max value every time the loop goes through a cycle. – Ceiling Gecko Mar 12 '14 at 08:15
  • is it possible to just show a waitdialog until while loop is in execution? – satnam Mar 12 '14 at 08:30

1 Answers1

0

As Ceiling Gecko said, first you have to count the total number of lines. Here can you find some possibilities.

After that you can create easily a progress dialog with a message with UiBooster, such as:

int totalLines = ...;
int currentLine = 0;

ProgressDialog dialog = new UiBooster().showProgressDialog("Please wait", "Waiting", 0, totalLines);
dialog.setProgress(currentLine);
milchreis
  • 79
  • 7