For two days, I'm struggling with this problem:
I'm developing a Java application.
The program shows an ordered list of objects in a Swing JList. These objects are obtained with a SQL query (SELECT.....ORDER BY...) to a MySQL database.
The user can add an object. This object is inserted on database by mean of "INSERT INTO....".
After the object is inserted in database, the JList is cleared, and the same "SELECT....ORDER BY...." query is executed in order to populate the JList again.
But the added object appears at the end of the list, instead it appear in order.
After I restart the application, the added object appears in correct order.
I can't imagine why this happens.
I don't know SQL and MySQL very well. May be I'm omitting some statements for persists the changes in database... I don't know.
I would suggest doing some debugging to observe what order the ORDER-BY query returns rows in. My wild guess, substantiated by looking at no code, is that you are populating the JList from something other than the database query the second time.
Thank you, for reply.
I use the same method to populate the JList from database in both cases: before and after the insertion.
I could make some debug:
I just print the order of the objects from the ResultSet I got from stored procedure: after the insertion, the added object appears in the last position.
But I executed the stored procedure from a console, and the object is in the correct position.
May be I have a remark: I'm using the same SQL Connection to execute both stored procedures: insertion and select.
Could this be a problem?