twg
asked on
clean-up resources
What is the best way to clean-up after an object that uses ResultSet,Connection and Statement objects?
I wrote close() method which closes these objects (by using their close method:Connection.close(), ResultSet. close() etc,
but I have to put all in a try block so what happens if an exception is thrown?
Another issue - what if the class which uses those objects is the main class
and no one calls its close() method?
I wrote close() method which closes these objects (by using their close method:Connection.close(),
but I have to put all in a try block so what happens if an exception is thrown?
Another issue - what if the class which uses those objects is the main class
and no one calls its close() method?
ASKER
thanks CJ S but I don't use ASP.
Anyway, the problems still stay open(if an exception is thrown, and how can I garantee clean-up for the main class
Anyway, the problems still stay open(if an exception is thrown, and how can I garantee clean-up for the main class
then what do you use, VBscript? That's also nothing
javascript is null
javascript:
object = null
vbscript:
object = nothing
asp = vbscript:
object = nothing
that'll ganarantue the clean up.
javascript is null
javascript:
object = null
vbscript:
object = nothing
asp = vbscript:
object = nothing
that'll ganarantue the clean up.
ASKER
I wrote my application in Java and it uses the java.sql package. I'm sorry that I didn't write my question in the right section (java programming) so can you pass my question to the relevant people?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wrote my application in Java and it uses the java.sql package. I'm sorry that I didn't write my question in the right section (java programming) so can you pass my question to the relevant people?
PART 1
_______
Use the finally clause....
try{
}
catch(Exeption e){
// handle exception
}
finally
{
// can clean up stuff here
}
EXCEPTION THROWN
If an exception occurs in the try block, and there is an associated catch block to handle the exception , control transfers to the catch block and then to the finally block
TRY BLOCK COMPLETES
If control reaches the end of the try , it then proceeds to the finally block.
PART 2
_______
You should really make sure that the close is called. But you can use the finalize()method. This method is called by the garbage collector calls before it collects the objects in memory. But there is a problem, you have no gaurantee that any objects will be garbage collected...
_______
Use the finally clause....
try{
}
catch(Exeption e){
// handle exception
}
finally
{
// can clean up stuff here
}
EXCEPTION THROWN
If an exception occurs in the try block, and there is an associated catch block to handle the exception , control transfers to the catch block and then to the finally block
TRY BLOCK COMPLETES
If control reaches the end of the try , it then proceeds to the finally block.
PART 2
_______
You should really make sure that the close is called. But you can use the finalize()method. This method is called by the garbage collector calls before it collects the objects in memory. But there is a problem, you have no gaurantee that any objects will be garbage collected...
Conn.Close
Conn = nothing