Generate New ID in java (GYANG) : Java
 

Forum :: Java :: Generate New ID in java (GYANG)

private void GetNEWID() {
        String str;
        String getdate;
        try {
            String ID = "SELECT MAX(BillID) AS AUTOID FROM dbo.Bill";
            pst = conn.prepareStatement(ID);
            rs = pst.executeQuery();

            while (rs.next()) {
                str = rs.getString("AUTOID");
                SimpleDateFormat DT = new SimpleDateFormat("yyyy");
                Date year = Calendar.getInstance().getTime();
                getdate = DT.format(year);
                if (str != null) {
                    String subString = str.substring(5, 15);
                    int x = Integer.parseInt(subString);
                    int y = x + 1;
                    String z = getdate + "-" + y;
                    txtbillid.setText("" + z);
 
                } else {
                    str = getdate + "-1000000001";
                    txtbillid.setText("" + str);
 
                }

            }

        } catch (SQLException ex) {
            int msg = JOptionPane.ERROR_MESSAGE;
            String tible = "@@@Security: G-YANG Warning!";
            JOptionPane.showMessageDialog(this, "Errer: Select statements: " + ex.toString(), tible, msg);
            return;
        }
    }

0 Comment

  • Have no comment.

Comment Forum

 
 
 
Share This Topic Login with Facebook