Closing a connection that is being passed in

Hi all I am hoping to get a bit of clarification on something. I am working with a database connection where there are methods that require information from other methods and so on. I am curious which would be better to have each method waiting with an open connection or to pass the connection as a parameter into the called method.

If passing the connection in makes sense I am assuming that each method will still be responsible for closing the connection on their own - would that be the right thought ?

thanks in advance

(The reason I put it here and not in the DB forum is I also wanted to get more than 1 or 2 thoughts about which method would be favoured more).

[695 byte] By [Aknibbsa] at [2007-11-27 5:15:49]
# 1

If you are going to pass a connection in, don't manipulate it inside the method that receives it. It should be passed for use only. It would be better to

// psuedo

conn = openConnection();

sqlMethod (conn);

conn.close();

Also since there are some standard operations with database interaction, you should create some kind of library, or database API to use for your application so that if something doesn't work, you will only need to change it in one place rather than 20 or so. In less words, Create a standard framework for database interaction.

kdajania at 2007-7-12 10:38:15 > top of Java-index,Java Essentials,Java Programming...