Hello, I'm new in java.
How I can connect mysql to JCombobox?
I already researched it but I really don't understand.
My JCombobox is inventcateg
my table is category
the column that I need in my JCombobox is categoryNo
here's my code:
I don't know where I will be putting codes to connect my JCombobox to mysql. Please help me.
package aaaaa; import java.sql.*; public class InventoryS extends javax.swing.JFrame { private Connection connect; public InventoryS() { initComponents(); try{ Class.forName("com.mysql.jdbc.Driver"); connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/aaaaa","root",""); statusTextArea.setText("Connection SUCCESSFUL!"); } catch (Exception f) {statusTextArea.setText(f.getMessage()); } } @SuppressWarnings("unchecked") private void formWindowClosing(java.awt.event.WindowEvent evt) { try { connect.close(); } catch(Exception f){}; } private void saveButton3ActionPerformed(java.awt.event.ActionEvent evt) { String inventcodef = inventCodeField.getText(); String inventnamef = inventNameField.getText(); String inventcateg = "Select categoryNo from category order by categoryNo; int inventreorderf = Integer.parseInt(inventReorderField.getText()); String inventlocf = inventLocationField.getText(); String inventstat = inventStatusArea.getText(); try { String SQL2 = "INSERT INTO inventory VALUES (" + "'" + inventcodef + "'" + "," + "'" + inventnamef + "'" + "," + "'" + inventreorderf + "'" + "," + "'" + inventlocf + "'" + "," + "'" + inventstat + "'" + ")"; PreparedStatement stamt = connect.prepareStatement(SQL2); stamt.executeUpdate(); statusTextArea.setText("Successfully saved!"); } catch (Exception f) { statusTextArea.setText(f.getMessage()); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new InventoryS().setVisible(true); } }); }
Thanks in advance!