Results 1 to 4 of 4
- 07-26-2012, 08:16 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 1
- Rep Power
- 0
java.lang.NullPointerException RegistrationServlet.doPost(RegistrationServlet.jav a:3
Please solve the error
below is the servlet code
import javax.servlet.http.*;
import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class LoginServlet extends HttpServlet
{
Connection con;
PreparedStatement ps;
public void init(ServletConfig config)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@loc alhost:1521:db", "system", "cad2010");
ps = con.prepareStatement( "SELECT * FROM register WHERE username = ? AND password=?");
}
catch(Exception e){}
}
public void destroy()
{
try
{
ps.close();
con.close();
}
catch (SQLException e)
{
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException
{
String user=req.getParameter("username");
String pwd=req.getParameter("password");
boolean b=false;
try
{
ps.setString(1,user);
ps.setString(2,pwd);
ResultSet rs=ps.executeQuery();
b=rs.next();
rs.close();
}
catch (SQLException e)
{ }
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<BODY BGCOLOR = red>");
if(b){
out.println("<H1> hello" +user+ "registered sucessfully</H1>");
}
else
{
out.println("<H2> The authentication failed</H2>");
}
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}
- 07-26-2012, 09:31 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: java.lang.NullPointerException RegistrationServlet.doPost(RegistrationServlet.ja
Moved from Advanced Java
What error? The stack trace should provide all the information to trace where it is thrown, and you did not provide it.Please solve the error
Two Comments:
1)
Never let exceptions fall through. At the very least print out the stack trace.Java Code:catch (SQLException e) { }
2) Please wrap code in the code tags
- 07-26-2012, 09:34 PM #3
Re: java.lang.NullPointerException RegistrationServlet.doPost(RegistrationServlet.ja
Why do they call it rush hour when nothing moves? - Robin Williams
- 07-27-2012, 09:20 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: java.lang.NullPointerException RegistrationServlet.doPost(RegistrationServlet.ja
Follow Darryl's links. You need to use [code] tags [/code] otherwise your formatting disappears in the forum and your code is very hard to follow.
Do not give a servlet attributes.Java Code:public class LoginServlet extends HttpServlet { Connection con; PreparedStatement ps; etc etc. }
It is not threadsafe, and is a bug in waiting.
Also follow doWhile's advice and printStackTrace() at the very least inside your catch blocks.
Something is going wrong and you are simply ignoring what.
I have my suspicions as to what exactly is up, but it would be guesswork.Please do not ask for code as refusal often offends.
Similar Threads
-
java.lang.NullPointerException
By Pombi in forum New To JavaReplies: 6Last Post: 05-15-2010, 03:12 PM -
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 3Last Post: 02-28-2009, 05:41 AM -
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 1Last Post: 02-27-2009, 12:36 PM -
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 2Last Post: 02-27-2009, 10:11 AM -
java.lang.NullPointerException
By stevemcc in forum AWT / SwingReplies: 2Last Post: 02-08-2008, 09:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks