File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

initialising db connection

 
nikil shar
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void establishDBConnection()


The return type is void, so I doubt if your code compiles
 
Somnath Mallick
Ranch Hand
Posts: 482
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the return statement in establishDBConnection()??
 
Sri Dharan
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be return Connection object :
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Importantly Change your class name from dbUtilities to DBUtilities
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic