I have a particular scenario where i have five methods in a class. All of the methods require to connect to database to perform some operation
So what i ideally want to do is have five operation specific methods and one DBMethod where i establish the connection and return back the connection object . i.e the signature would be like
public Connection DBObject(){ //Establishing connection with a type 4 driver
then in the other five operation specific methods i just say
Connection connection = DBObject();
However this approach is not working and i am getting a null pointer exception as the DBObject() method is not able to return a connection object.
i cannot understand as to why this is happening. Also is this the right approach from the design perspective. If not please let me know what's the right approach.
In the DBConnect class you already have a field for Connection connection. Then in the DBConnection method why again you are creating a connection variable. Just use the above.
Code to be modified:
[Added code tags - Dave] [ July 24, 2008: Message edited by: David O'Meara ]