简体   繁体   中英

java - show progress dialog of importing to database

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM