I'm trying to make unique auto-generated ID using combination of char, date, and value. This is my code :
int getValue;
public void generateNOS(String query) throws SQLException {
try {
Connection con = koneksi.koneksiDB();
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery(query);
if (rs.next()) {
getValue = Integer.parseInt(rs.getString(5));
}
} catch (Exception e) {
}
}
public void autonumberNOS() throws SQLException {
generateNOS("SELECT count(no_surat)+1 FROM surat_masuk");
try {
String NOS = "NOS/1/"+new SimpleDateFormat("yyyyMMdd").format(new Date())+"/"+getValue;
txtNOS.setText(NOS);
} catch (Exception e) {
}
}
For example, the ID supposed to "NOS/1/20181120/1". But i got "NOS/1/20181120/0". What was missing ? Is the SQL syntax wrong ? Thanks for any help.