• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Results are being retained in memory!

 
Chad Saviola
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a (relatively) simple problem for which I'm seeking help for.

In my database bean (db_connector) I have a method (supplyTopSix) that queries and returns values from a mysql database (which successfully happens).

In another java class, I call this method, by supplying it an SQL string, and the data is returned (again, successfully).

From a JSP, I call this method and display the data returned by the query (again, successfully). However, if I refresh the JSP page, the results are returned twice (i.e. data is printed out, and then printed out again). This pattern keeps happening corresponding to the number of times I refresh the page.

I understand that the medthod in the db_connector bean is being run again and again, but how do I overcome this?

I tried creating another method (getTopSix) which simply returns the returned variable from db_connector, but if I call the getTopSix method from the JSP, it doesnt display anything, unless the supplyTopSix method has been run once (which I can run myself, but when my application is packaged as a *.war file, I cant see how I could get the supplyTopSix method to be run 'automatically' so it can be used by getTopSix)!

Here are my two methods:
------
------
public String getTopSix()
{
return topSixTeams;
}
------
------
------
public String supplyTopSix()
{

db_connector.setSettings(url, driver, un, pw);
Vector results = db_connector.getRecords("select * from tblTeams ORDER BY points DESC LIMIT 6");
for (int i=0; i<results.size(); i++)
{
topSixTeams += "<tr>";
Vector row = (Vector)results.elementAt(i);
for (int j=1; j<row.size(); j++)
{
topSixTeams += "<td>" + row.elementAt(j).toString() + "</td>";
}
topSixTeams += "</tr>";
}

return topSixTeams;
}
------
------
------

Can anyone help with this issue ?

Any input is greatly appreciated.

Thanks.
C.Saviola
 
Chad Saviola
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it could be a case of setting the variable to 'nothing' at the beginning of the method?

so:

public String supplyTopSix()
{
topSixTeams = "";
.
.
.
}

...will give this a go, but input is appreciated!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic