jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes java.lang.NullPointerException at doPost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.lang.NullPointerException at doPost" Watch "java.lang.NullPointerException at doPost" New topic

java.lang.NullPointerException at doPost

Shantanu Kulkarni

Joined: Feb 19, 2014
Posts: 4
Hi there,

I recently started java programming, so yes, i'm a greenhorn.
I'm getting java.lang.NullPointerException at doPost() method in my serlvet. Code is posted below. can anyone help me please?
Console says, it is at> pst = con.prepareStatement("SELECT EMPNAME, EMPID FROM EMPLOYEES WHERE EMPNAME= ? AND EMPID= ?"); (line#65 in the below code.)

I'm using oracle 10g. username, password, host string, url etc are correct. i can see the values in table.


William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13025
Oh so many problems....

You have defined and instance variable con in line 20

Then another Connection con in the init method - so naturally the instance con remains null

You need to realize that programming for servlets requires a mental switch from programming for desktop applications.

Shantanu Kulkarni

Joined: Feb 19, 2014
Posts: 4
Thanks. I did not realize i declared 'con' twice
It is sorta covered in the JavaRanch Style Guide.
subject: java.lang.NullPointerException at doPost
It's not a secret anymore!