The invoices table is linked to the provider table by the provider_id field, but when I insert data, I get a foreign key error, and tried in CASCADE, RESTRIC etc mode and it does not work, validate that the IDs of the tables be primary keys, the second point is that I do not know how to fill a comboBox with the data from the suppliers table so that the ones already created can be chosen in the invoice form. Who can help me?
SELECT to see the table :
//En esta instruccion sSQL se realizara el inner join de las 2 tablas proveedor y factura
sSQL = "SELECT f.id_factura, f.consecutivo, f.id_proveedor, f.producto,"+
" f.cantidad,f.fvalor, f.fechaini, f.fechafin, f.concepto, p.id_proveedor,"+
" p.empresa, p.nit FROM tfacturas f INNER JOIN tproveedores p ON "+
"f.id_proveedor = p.id_proveedor WHERE p.nit like '%"+ buscar +"%' order by id_factura";
INSERT for the table:
public boolean insertar(Tfactura dts) throws SQLException {
sSQL = "INSERT INTO tfacturas (consecutivo, id_proveedor, producto," +
" cantidad, fvalor, fechaini, fechafin, concepto)" +
" values (?,?,?,?,?,?,?,?)";
try {
PreparedStatement pst = cn.prepareStatement(sSQL);
pst.setString (1, dts.getConsecutivo());
pst.setInt (2, dts.getId_proveedor());
pst.setString (3, dts.getProducto());
pst.setDouble (4, dts.getCantidad());
pst.setDouble (5, dts.getFvalor());
pst.setDate (6, dts.getFechaini());
pst.setDate (7, dts.getFechafin());
pst.setString (8, dts.getConcepto());
int n = pst.executeUpdate();
if (n != 0) {
return true;
} else {
return false;
}
} catch (Exception e) {
JOptionPane.showConfirmDialog(null, e);
}
return false;
}