I want to create a method that generates an invoice number.
I do not increase it in the DB because it is not recommended and I have decided to create a char varying field where I store or add 1 to the query in postgres.
public Cliente numOrden() {
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = getConexionTemporal();
// Preparamos la consulta
String sql ="select cli_num from cliente where cli_num=cli_num";
try {
// Traemos los datos de la bd
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
// Cargamos los resultados
if (rs.next()) {
Cliente cliente = new Cliente();
cliente.setNumeroOrden(rs.getString("cli_num"));
return cliente;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
cerrarObjeto(con);
cerrarObjeto(rs);
cerrarObjeto(ps);
}
return null;
}
The controller where I show the invoice number:
private void cargarOrden(){
SentenciasSQL registro = new SentenciasSQL();
Cliente cliente = registro.numOrden();
txtFactura.setText(cliente.getNumeroOrden());
System.out.println(cliente.getNumeroOrden());
}
If you help me with any idea or how it would be easy, I want it to be 00001 and follow 00002 etc.