I have a database query to complete which will return a result set that I will then parse through and retrieve the values from the set.
I have created a class called "obQuery". As part of the constructor, I am generating the objects to create the query and then have created a method called "getResultSet", within the main class, that generates the "ResultSet" object from the SQL statement.
When I instantiate the "obQuery" object, I'd like to be able to retrieve the results of the ResultSet. I am lost though because, if I call the "getResultSet" method, that method has to know which SQL statement to run and the calling code does not know that value.
How can I create an empty ResultSet object and populate it with the output of the "getResultSet" code, without having to pass in the values to the method?
I'm not sure if I understood your actual question: is it something like: "how to make use of the variables passed to the constructor in the getResultSet() method, so that once created, a dbQuery instance can return the result by simply calling getResultSet() -- with no parameters ?"
If so, I'll try to answer this question alone and just remind you that a class can hold state as instance variables.
Therefore, you can keep the queryTerm you get in the constructor and the Statement you are creating as instance variables
(I'm just pointing out a solution for your particular concern, assuming I got it right, as storing a Statement as an instance variable is a... "second best" practice, so to speak)
Again, as Mohamed pointed out, there is a lot to reconsider about your code, but I'd say let's clarify them one at a time...
Joined: May 11, 2009
Thanks to you both. I'll go back and look at how I am approaching this problem.
As i can see taht you are returning the ResultSet itself from the Method .
This is a bad practice , you should not keep ResultSet open for that much long . (Because this involves Database related stuff also Open )