aspose file tools*
The moose likes JDBC and the fly likes Can't Perform Same Search Twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can Watch "Can New topic
Author

Can't Perform Same Search Twice

Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
Hello Ranchers. I have an application that executes a SQL query using JDBC and the jTDS driver. It then stores the results of the query in a two-dimensional string array and closes the connections:


When I do another search with different search criteria, everything seems to work fine. However, if I do the exact same search a second time, the array of results seems to hold onto the previous data. I'd imagine that I may need to destroy the existing array somehow, though I thought that re-instantiating serves the same purpose. Does anyone know what could be causing this? Thanks!
[ May 14, 2007: Message edited by: Scott Florez ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


However, if I do the exact same search a second time, the array of results seems to hold onto the previous data.

If you are doing the exact same search a second time, shouldn't the results be identical?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
Originally posted by Paul Sturrock:

If you are doing the exact same search a second time, shouldn't the results be identical?


No, because the database is updatable and is accessed my multiple users simultaneously. So on a large search, there's a decent chance something may have changed since the previous search. Plus, I don't use "order by" in my SQL query, so the results will come back in a different order every time.
[ May 14, 2007: Message edited by: Scott Florez ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


No, because the database is updatable and is accessed my multiple users simultaneously. So on a large search, there's a decent chance something may have changed since the previous search.

A "decent chance"? Has it actually been updated?
Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
After playing with my application some more, I don't think I originally described my problem properly, so let me try again.

My application does SQL queries using the code I posted above and displays a summary of the results in a summary screen with the ability to iterate through the records 25 at a time (which are stored in a 2D string array). Then, the user can select a record's summary and click a button to view its details (which are selected from the array using it's index number).

Upon the first search, everything works properly. Upon a second search, everything works until the user clicks the details button. Then, a totally different (and seemingly random) record is displayed instead of the one the user wanted to view. Restarting the application will always allow the same search to work properly the first time, but then subsequent searches fail.

I know the right index number is being referenced when the user selects the details. It's as if the data in the array are shifting around somehow.

Let me know if you'd like to see any additional code. Thanks everyone.
[ May 14, 2007: Message edited by: Scott Florez ]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
It would help to if you can provide some additional code. With the code provided i guess some variable is not getting initialized properly. Does this method also references any instance/class variables.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I know the right index number is being referenced when the user selects the details. It's as if the data in the array are shifting around somehow.

Sounds like you have out of date data in your array, or the array index is messed up some how.

Just out out interest, why did you use a 2D array, and not an easier to work with Collection?

Can you show us some more code?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't Perform Same Search Twice