简体   繁体   中英

How i can get max value of this increment?

I have increment syntax, and i want to save the last maximum value , so when i close my program and open it again , the increment will start from the last maximum value not start from 0 again .. but here my syntax always start from 0 again, so what to do ?

   private long l = 100000;
   view.getRdbtnUmum().addActionListener(new ActionListener() {


    @Override
    public void actionPerformed(ActionEvent e) {



        if(view.getRdbtnUmum().isSelected() == true){
            view.getRdbtnPrestone().setSelected(false);
            view.getTxtJobCode().setValue("JU" + l);

        }       
        l++;
        model.setjPres(l);

    }
});

You need to persist the last value somewhere. You can simply choose to write it on a simple file or you can persist it in a DB.

If you can use the last maximum value, you can save the value to the file or database.

To save the value into file:

 public static void serializeSumNum(int sum){         
             ObjectOutputStream oos = null;
               try{

                FileOutputStream fout = new FileOutputStream("D:\\sum\\sum.txt");
                 oos = new ObjectOutputStream(fout);   
                oos.writeObject(sum);

                System.out.println("Done");

               }catch(Exception ex){
                   ex.printStackTrace();
               }
finally {
                //Close the ObjectOutputStream
                try {
                    if (oos != null) {
                        oos .flush();
                        oos .close();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
           }

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