This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't Perform Same Search Twice

 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic