auto number + caracter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

auto number + caracter

wahid
This post has NOT been accepted by the mailing list yet.
Tolong bantuannya gan,
Ane mao bikin nomor transaksi di hibernate, caranya gmn yak?
Contoh : TRS-01.
Terima kasih agan2 sebelumnya
Reply | Threaded
Open this post in threaded view
|

Re: auto number + caracter

fransiscusgea
This post has NOT been accepted by the mailing list yet.
   void nomorotomatis(){              
       try{                  
        Connection con = koneksi.getConnection();
        String sql = "select MAX(right(kodepo,3)) As kodepo from tablepo";
            res = stat.executeQuery(sql);
            while(res.next()){
                if(res.first()== false){                
                    txkodepo.setText("00001");                
                }
                else{
                    res.last();
                    int kdp = res.getInt(1)+1 ;
                    String koder = String.valueOf(kdp);
                    int panjang = koder.length();
                    for (int i=0; i <3-panjang; i++){
                        koder = "00"+koder;                    
                    }
                    txkodepo.setText("PURC - "+ttanggal.getText()+" - "+koder); //hasilnya :PURC - + tanggalsekarang + nomor urut              
                }
            }
        }
        catch (Exception e){
           
            //JOptionPane.showMessageDialog(rootPane, "" +e);
           
        }
    }