aspose file tools*
The moose likes Servlets and the fly likes initialising db connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "initialising db connection " Watch "initialising db connection " New topic
Author

initialising db connection

nikil shar
Ranch Hand

Joined: May 25, 2008
Posts: 116
hi all,
have got a servlet which calls a utilities class to initialize db connection. inside the utilities class my method looks like this :




when i call this method from my servlet :



i get a null pointer returned. i can see that "dbUtil.establishDBConnection()" returns an object but for some reason it never gets assigned to 'con' object in my servlet !!


any help would be much appreciated.

ta.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

public void establishDBConnection()


The return type is void, so I doubt if your code compiles


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Where is the return statement in establishDBConnection()??
Sri Dharan
Ranch Hand

Joined: Aug 21, 2008
Posts: 74
It should be return Connection object :
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

You are probably getting the DS on the first try and assigning the connection when the DS is not null on the second try. The second call probably does not return null, but we can only speculate since the code and the problem at hand do not match each other
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Importantly Change your class name from dbUtilities to DBUtilities
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: initialising db connection