aspose file tools*
The moose likes JDBC and the fly likes java.lang.NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.lang.NullPointerException" Watch "java.lang.NullPointerException" New topic
Author

java.lang.NullPointerException

polavarapu prasad
Greenhorn

Joined: May 16, 2012
Posts: 2
when i try to execute it on server it shows java.lang.NullPointerException so please help me in solving this problem

thanks in advance
durga prasad


login html

<html>
<body bgcolor=lime>
<br><br><br>
<center>
<form method="POST" action="/connection/ServletConnection">
<pre>
user id :<input type="text" name="user" size="20">
password :<input type="password" name="pswd" size="20">
<input type="submit" name="login" value="signin"></pre>

</form>
</center>
</body>
</html>



ServletConnection servlet




web xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>Zulfiqar</servlet-name>
<servlet-class>ServletConnection</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Zulfiqar</servlet-name>
<url-pattern>/ServletConnection</url-pattern>
</servlet-mapping>
</web-app>




Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Look at your stacktrace and see which line number and class the exception originates from.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

remember it is always good practice to do null check before rs.next as in
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

That's not necessary. Statement.executeQuery will never return null.

Polavarapu, are you sure that s3 and s4 will never be null?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Rob Spoor wrote:That's not necessary. Statement.executeQuery will never return null.


I dont know that. just referred the java doc. so far the projects i see, they do the null check, so i misunderstood.

thanks rob
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

The Javadoc is clear about never returning null, so any example that checks for null as a redundant null check.

And you're welcome of course
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
A sidenote: it is not a good idea to declare these
as instance variables of the servlet.
A servlet instance might serve different requests in different threads.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.lang.NullPointerException