Shouldn't I be able to reuse an object? My results are always the same. (The QueryClass connects to a database and returns the result as a String.)
Here's an example: QueryClass queryObj = new QueryClass(); String queryObjString_1 = queryObj.QueryClass("select id from user").toString(); String queryObjString_2 = queryObj.QueryClass("select name from user").toString(); Here are the incorrect results (they should not be the same): queryObjString_1 = 52145 queryObjString_2 = 52145 -------------------------------------- However, it works when I do this: QueryClass queryObj_1 = new QueryClass(); String queryObjString_1 = queryObj_1.QueryClass("select id from user").toString(); QueryClass queryObj_2 = new QueryClass(); String queryObjString_2 = queryObj_2.QueryClass("select name from user").toString(); Here are the correct results: queryObjString_1 = 52145 queryObjString_2 = Dave Any help would be greatly appreciated.
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
You seem to be using QueryClass both as a Constructor and as a method somehow. It would be interesting to see your QueryClass definition. If you post it please enclose the code between UBB code brackets which you get by using the CODE button sited under the edit box.
Hello, That is exactly what I am doing. I guess it's incorrect? Here's my class:
Billybob Marshall
Ranch Hand
Joined: Jan 27, 2004
Posts: 202
posted
0
A couple of problems: 1) Your method name should not be the same as the class name. Name it something according to what it does, like 'doQuery' for example. 2) Your 'result' class member should probably be moved inside the method to be just a normal method variable (afterall, is it referenced by any other methods, or is the previous value of importance?) That said, My guess would be that the second time the method executed, it didn't change the 'result' reference - maybe you conditionally set it (which you're not showing in the snippet you posted)? Otherwise it should have worked as desired (albeit sloppily).
David Ogasawara
Greenhorn
Joined: Oct 11, 2001
Posts: 13
posted
0
Thank you for pointing me in the right direction. That's something I really needed. -Dave
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.