• Post Reply Bookmark Topic Watch Topic
  • New Topic

connection is null resulting in NullPointerException  RSS feed

 
Andrei Robert
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CitesteDatele.java




HTTP Status 500 -

type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
CitesteDatele.processRequest(CitesteDatele.java:73)
CitesteDatele.doGet(CitesteDatele.java:144)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

Apache Tomcat/7.0.47

 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your connection never was initialized.

like this way:



Try debug it and see your object "con" at the exact moment
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try call your method init()

No, don't do that. Edson may not be aware that the init() method is called as part of the initialization of a servlet that extends HttpServlet. But something else may well have gone wrong. For example, there's a typo in line 47.

Is anything written to the log files due to exception being thrown?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, never do this, regardless of how many servlet tutorials make the same mistake:

Treating GET and POST interchangeably goes against the HTTP specification. Since your code is writing to the DB it should only be accessible via PoST, not via GET.

And your code is wide open to SQL injection attacks, you need to get into the habit of using PreparedStatement.
 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
Try call your method init()

No, don't do that. Edson may not be aware that the init() method is called as part of the initialization of a servlet that extends HttpServlet. But something else may well have gone wrong. For example, there's a typo in line 47.

Is anything written to the log files due to exception being thrown?


Sorry, I corrected my post
 
Andrei Robert
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
Try call your method init()

No, don't do that. Edson may not be aware that the init() method is called as part of the initialization of a servlet that extends HttpServlet. But something else may well have gone wrong. For example, there's a typo in line 47.

Is anything written to the log files due to exception being thrown?


Thanks.... in line 47 need com and not con... inadvertently...

Thank you all ;))
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!