This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 12761
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
Similar Threads
How to configure Bonecp in java project without breaking connection when more than connection
user registration via Servlet/JSP/JDBC
How to insert value in a table using session(ArrayList)?
about hidden from fields
Servlet Update Code