我如何获得这个增量的最大值?

时间:2022-09-26 21:12:37

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 ?

我有增量语法,我想保存最后一个最大值,所以当我关闭我的程序并再次打开它时,增量将从最后一个最大值开始,而不是从0再次开始..但是这里我的语法总是从0开始再来一次,那该怎么办?

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

    }
});

2 个解决方案

#1


0  

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.

你需要在某个地方保留最后一个值。您可以简单地选择将其写在一个简单的文件上,也可以将其保存在数据库中。

#2


0  

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

#1


0  

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.

你需要在某个地方保留最后一个值。您可以简单地选择将其写在一个简单的文件上,也可以将其保存在数据库中。

#2


0  

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