Please solve my error occured java.lang.NullPointerExceptio
This is my code: I figured out the else part of the code causing this error. But i don't understand what is that. Can anyone solve this. Any kind of help suggestion will be appreciated. Thanks
Code :
<%@ page import="INCLUDES.DBConnection"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="DB" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB" property="*"/>
<%
String user_name=request.getParameter("user_name");
ResultSet objRs=null;
String statement="";
try
{
statement="select * from x_master_elearning_user where user_name='" +
user_name + "'";
DB.setStatement(statement);
objRs=(ResultSet)DB.resultUpdate();
if(objRs.next())
{
response.sendRedirect("signup.jsp");
}
else
{
objRs.updateString("user_name",user_name);
objRs.updateString("pass_word",request.getParameter("pass_word"));
objRs.updateString("first_name",request.getParameter("trainee_name"));
objRs.updateString("designation",request.getParameter("designation"));
objRs.updateString("email",request.getParameter("email"));
objRs.updateString("city",request.getParameter("city"));
objRs.updateString("country",request.getParameter("country"));
objRs.insertRow();
response.sendRedirect("course_list_index2.jsp");
}
}
catch(Exception e)
{
out.print("error occured " + e);
}
%>
Re: Please solve my error occured java.lang.NullPointerExceptio
Hello there,
First of all could you tell us where you are getting the nullpointer? It could be because there is no resultset so objRs.next will throw a nullpointerexception.
On another note I see that you're grabbing the username off the request parameters and passing it into your SQL query, this is a MAJOR security hole and you are effectively giving anyone access to everything in your database.
See SQL injection - Wikipedia, the free encyclopedia
You should be using PreparedStatement instead and not concatenate your SQL query with user input variables.
// Json