I have two tables with the same fields and I'm using two equal methods for each insert in each table the only thing that changes is the name of the table. I would like to reuse the code just by changing the name of the table through a combobox. Is there any way?
public int insertarHerra(String nombreHerra, String descripcionHerra, int stockHerra, String fechaAdquisicion) {
conectando = Conectar.getConnection();
//System.out.println(nombre);
try {
String sql = "insert into herramientasalmacen(nombreHerra, descripcionHerra, stockHerra,fechaAdquisicion) values(?,?,?,?)";
preparando = conectando.prepareStatement(sql);
preparando.setString(1, nombreHerra);
preparando.setString(2, descripcionHerra);
preparando.setInt(3, stockHerra);
preparando.setString(4, fechaAdquisicion);
int dato = preparando.executeUpdate();
return dato;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Ocurrio un error al registrar usuario.");
}
return 0;
}
/////////////////////////////////////INSERTAR CONSUMIBLES////////////////////////////////////////////////////////
public int insertarConsu(String nombreConsu, String descripcionConsu, int stockConsu, String fechaAdquisicion) {
conectando = Conectar.getConnection();
//System.out.println(nombre);
try {
String sql = "insert into consumiblesalmacen(nombreConsu, descripcionConsu, stockConsu,fechaAdquisicion) values(?,?,?,?)";
preparando = conectando.prepareStatement(sql);
preparando.setString(1, nombreConsu);
preparando.setString(2, descripcionConsu);
preparando.setInt(3, stockConsu);
preparando.setString(4, fechaAdquisicion);
int dato = preparando.executeUpdate();
return dato;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Ocurrio un error al registrar usuario.");
}
return 0;
}