Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

DB connection and a null pointer exception

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone,

If you guys don't mind reading some code i need some suggestions as to why i am receiving a NullPointer Exception.
Tomcat says it encountered an internal error.

Ive narrowed the problem down to line 41, in the DataAccess class. I don't understand why this is giving me a problem because ive use this code before in a java gui and no problems..

This is my first shot at servlets so some advice would help me a long way.

Thanks

Servlet


DataAccess Class

 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 41? Then the error is simply that the variable "statement" is null. You haven't ever set it to anything other than null.

The only place you might set it is Line 10. But if Line 7 throws an exception then that line would never be executed. That's my guess about what really happened.

And it makes no different that this code happens to be in a servlet, or called from a servlet. It's just Java programming so let's move the thread there.
 
Joe Deluca
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya you were right, i forgot to put in the J Connector
thanks
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic