Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I see the problem in your code. Your code is extremely strange but here's what I think is happening:</p> <p>In your <code>ViewStockQuery</code> class, you have the <code>retrieveStock()</code> method. This method then creates an instance of your GUI class, <code>ViewStockGUI</code>. Apart from this being bad practice, it leads to a problem here because in the constructor of the <code>ViewStockGUI</code>, which you called in the <code>retrieveStock()</code> method in this line:</p> <pre><code>stockGUI = new ViewStockGUI(); </code></pre> <p>you then again call <code>retrieveStock()</code> with this line:</p> <pre><code>final ViewStockQuery stock = new ViewStockQuery(); comboGUI = stock.getComboBox(); stock.retrieveStock(); </code></pre> <p>This leads to a recursive issue as your <code>ViewStockGUI()</code> constructor calls the <code>retrieveStock()</code> method which creates a connection and again calls the <code>ViewStockGUI()</code> constructor which will again call the <code>retrieveStock()</code> method that hasn't closed the connection and tries to open a different connection. Hope you get the picture.</p> <p>A way to solve it is to clean up your code. Don't call the constructor in <code>retrieveStock()</code>. Find a different way to pass the selected category for your query.</p> <p>Edit:</p> <p>Write you <code>ViewStockQuery</code> like so:</p> <pre><code>private String mSelected; public ViewStockQuery(String selectedCategory) { mSelected = selectedCategory; } ... public void retrieveStock() throws SQLException { con = SQLConnect.getConnection(); String viewStock = "SELECT * FROM Stock where categoryName = '" + "'" + mSelected + "'"; System.out.println(viewStock); try { ... </code></pre> <p>Then write your <code>ViewStockGUI</code> in such a way that when a category has been selected, that is when you create the <code>ViewStockQuery</code> and pass in the selected string.</p> <p>Edit:</p> <p>Like I said before, there are quite a lot of things you will eventually need to change in your code. But, for the purpose of this issue, what you could do is in your <code>ViewStockGUI</code>, do:</p> <pre><code>String selected = (String)combo.getSelectedItem(); final ViewStockQuery stock = new ViewStockQuery(selected); </code></pre> <p>The first line collects the selected category from your combobox and the second line creates an instance of <code>ViewStockQuery</code> and passes the selected to the constructor. This will then initialize mSelected as you see in the constructor I put above for <code>ViewStockQuery</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload