java load values from database into comboBox -
Hi, My purpose is to load the combobox with the voices from a database, the code below works fine with a problem, I already get two items, so what should I do to stop it
Public Zero LoadCombs () {try {string cs = "jdbc: mysql: // localhost: 3307 / booksalvation6"; String user = "root"; String password = "latein"; JComboBox2.removeAllItems (); // Make sure the old data has been prepared; Statement pstpost; As a result rspost; ConCombos = DriverManager.getConnection (CS, User, Password); (Int i = 1; i & lt; 11; i ++) {string query pst = "select from post" + "WHERE postage_id =" + i; // Load Postage Selection pstpost = conCombos.prepareStatement (querypost); Rspost = pstpost.executeQuery (); Whereas (rspost.next ()) {string myopost = rspost.getString (6); JComboBox2.addItem (Mypost); }}} Hold (SQLException pre) {Logger.getLogger (BasicFrame.class.getName ()). Log (Level.SEVERE, null, ex); } ConCombos.close (); } Hold (SQLException pre) {Logger.getLogger (BasicFrame.class.getName ()). Log (Level.SEVERE, null, ex); }}
You are using the created location
but not in the right
Since you are looking to get all the column values for only one column, which are postage_id between 1 and 10.
You can find it in a single question:
postage_id> = Select unique (combo_value_column_name) from the post? And postage_id & lt; =?
Set parameters by calling it 1 and 10.
Simply bring single column and only unique value .
To complete the java tutorial , then complete the entire list once it's finally set.
Last Note: Follow the Java Naming Convention.