title: How To Make Auto Increment Number Java
body: <p>I'm making method for automatic number but this number is stuck only to number P-011. How to fix it ?</p>
  
  <pre><code>private void outomatic_number(){
          try {
              open_db();
              String sql="select right (no_rm,2)+1 from pasien";
              ResultSet rs=stm.executeQuery(sql);
              if(rs.next()){
                  rs.last();
                  String no=rs.getString(1);
                  while (no.length()&lt;3){
                      no="00"+no;
                      txtno.setText("P-"+no);}
                  }
              else
              {
                 txtno.setText("P-001"); 
              }
              } catch (Exception e) 
              {
          }
      }
  </code></pre>