Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Please solve my error occured java.lang.NullPointerExceptio

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    <%@ 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);
    	}
    %>


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default 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

Similar Threads

  1. java.lang.numberformatexception error
    By natalie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 19th, 2010, 04:16 AM
  2. Replies: 1
    Last Post: January 15th, 2010, 01:32 AM
  3. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  4. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  5. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 11:46 PM