Im trying to make a database but my only problem is the jComboBox. If i want to change the deliver company its not showing the correct company that the person has like in the Picture That’s the example problem i have
I have a similar Code that i compared and which I searched for my mistake. I found it but can’t correct it because i don’t know WHY it’s not working and how to fix.
Im sorry if i missed something just write it down and I’ll add it afterwards.
Here is the Code of the jCombobox
private void initComboboxVersand(List<VersandDTO> vrsndList) {
int indexOfSelectedVersand = 0;
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 5;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(11, 25, 11, 26);
for (int i = 0; i < vrsndList.size(); i++) {
jComboBoxVersand.addItem(vrsndList.get(i));
if (vrsndList.get(i).getVersandid() == versandid) {
indexOfSelectedVersand = i;
}
}
getContentPane().add(jComboBoxVersand, gridBagConstraints);
jComboBoxVersand.setSelectedIndex(indexOfSelectedVersand);
}
here is the code from the constructor
public ChangeVint(java.awt.Frame parent, boolean modal, List<VersandDTO> versand, int benutzerid, String bntzername, String vorname, String nachname, String artikelart, String preis, int versandid, String kaufdatum) {
super(parent, modal);
initComponents();
initComboboxVersand(versand);
this.benutzerid = benutzerid;
this.bntzername = bntzername;
this.vorname = vorname;
this.nachname = nachname;
this.artikelart = artikelart;
this.preis = preis;
this.versandid = versandid;
this.kaufdatum = kaufdatum;
//filling the text Fields
fillTextField();
}
Here is the code from the change() method to change it inside the database
private void change() throws SQLException {
Connection conn = DriverManager.getConnection(dbconnection, "root", "");
String strInsert = "UPDATE verkauft "
+ "SET BenutzerID = ?, "
+ "Vorname = ?, "
+ "Nachname= ?, "
+ "Benutzername = ?,"
+ "Artikelart = ?,"
+ "Preis = ?,"
+ "VersandID = ?," // <-- thats for the Company id
+ "Kaufdatum = ?"
+ "WHERE BenutzerID = ?";
PreparedStatement stmt = conn.prepareStatement(strInsert);
stmt.setInt(1, Integer.parseInt(txtID.getText()));
stmt.setString(2, txtVorname.getText());
stmt.setString(3, txtNachname.getText());
stmt.setString(4, txtBntzername.getText());
stmt.setString(5, txtArtikelart.getText());
stmt.setString(6, txtPreis.getText());
stmt.setInt(7, ((VersandDTO) getjComboBoxVersand().getSelectedItem()).getVersandid());
stmt.setDate(8, new java.sql.Date(dateChooser.getDate().getTime()));
stmt.setInt(9, benutzerid);
stmt.execute();
}
Im not the best coder but i hope you understand it. Thanks for the help