| Author |
Null pointer exception when accessing database
|
Vic Hood
Ranch Hand
Joined: Jan 05, 2011
Posts: 477
|
|
Hi Folks,
Ive been trying to create a mini crud sample using JSP's ,however Im getting a null pointer exception upon trying to insert into the database . Upon checking I found that the request object does contain the passed data, however the same leads to a NPE when inserting to the DB , ive placed the code below. Any help would be great.
Thanks a lot!
Thanks for helping out!
|
Learning and Learning!-- Java all the way!
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
|
Moved to the JDBC forum.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Vic Hood
Ranch Hand
Joined: Jan 05, 2011
Posts: 477
|
|
Thought it was relevant to JSP forums as it was a JSP page . Anyways , help would be much appreciated as its very very urgent . .Thanks .
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
Vic Hood wrote:Hi Folks,
Ive been trying to create a mini crud sample using JSP's
Thanks for helping out!
I know you are just doing a sample, but it is wrong approach to do this inside of a JSP. You are aware this connection stuff should be done in Servlet, right?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
You create a Connection variable "con" and assign null to it.
Later you try to use it to create a PreparedStatement. It's still null so you get that exception.
|
 |
Vic Hood
Ranch Hand
Joined: Jan 05, 2011
Posts: 477
|
|
Paul Clapham wrote:You create a Connection variable "con" and assign null to it.
Later you try to use it to create a PreparedStatement. It's still null so you get that exception.
Hi Paul ,
Thanks. For replying . I do understand your point . But can't seem to figure out how to solve it , :( . Could you please suggest a work around, to avoid the NPE ? Thanks a lot .
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
Vic Hood wrote: Could you please suggest a work around, to avoid the NPE ? Thanks a lot .
why not get rid of con entirely and just use connection?
|
 |
Vic Hood
Ranch Hand
Joined: Jan 05, 2011
Posts: 477
|
|
Thanks a ton Tim ! That solved the problem
|
 |
 |
|
|
subject: Null pointer exception when accessing database
|
|
|