Friends, I am trying to generate an autoincrementable Registration Number with a certain structure ... The first two numbers correspond to the current year that is added 000000 (5 zeros) and that must be autoincrementando for each record that is added ... and in addition to that to meet a new year must return to zero and the first two number must also change ... REMAINING LIKE: 1800001
I tried to do it in an archaic way and it has not worked out for me, since it is adding the year again, remaining in 18181800005
DateFormat df = new SimpleDateFormat("yy");
String formattedDate = df.format(Calendar.getInstance().getTime());
String sql = "SELECT LAST_INSERT_ID(nregistro)+1 as nregistro
FROM muestras ORDER BY nregistro DESC LIMIT 1";
try {
java.sql.Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
texto_registro = rs.getString("nregistro");
System.out.println(" texto registro");
if (texto_registro == null) {
// lb_registro.repaint();
lb_registro.setText("000001");
lb_registro.repaint();
}
}if (year == ahora) {
lb_registro.setText(formattedDate + texto_registro);
System.out.println("registro");
} else {
lb_registro.setText(formattedDate + "000001");
lb_registro.repaint();
}
} catch (SQLException e) {
Logger.getLogger(Ladiox_Insertar.class.getName()).log(Level.SEVERE, null, e);
}
}