GeeCON Prague 2014*
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


JavaRanch » Java Forums » Java » Servlets
Bookmark "java.lang.NullPointerException at doPost" Watch "java.lang.NullPointerException at doPost" New topic
Author

java.lang.NullPointerException at doPost

Shantanu Kulkarni
Greenhorn

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.



LoginServlet.java


Console:
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
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.

Bill
Shantanu Kulkarni
Greenhorn

Joined: Feb 19, 2014
Posts: 4
Thanks. I did not realize i declared 'con' twice
 
GeeCON Prague 2014
 
subject: java.lang.NullPointerException at doPost