while(rslogin.next()) creates error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pravipravi
    New Member
    • Feb 2007
    • 16

    #1

    while(rslogin.next()) creates error

    [HTML]id=request.getP arameter("txtId ");
    51: pwd=request.get Parameter("txtP wd");
    52: rslogin=getAllD ata("select * from login where username='"+id+ "' and password='"+pwd +"'");
    53: while(rslogin.n ext())
    54: {
    55: flag=1;
    56: session.setAttr ibute("UserId", id); [/HTML]
    The above given is my coding.In my login table i have username and password.
    But when iam excecuing the application with Tomcat following error is occuring.

    org.apache.jasp er.JasperExcept ion: An exception occurred processing JSP page /myLogTest.jsp at line 53

    Stacktrace:
    org.apache.jasp er.servlet.JspS ervletWrapper.h andleJspExcepti on(JspServletWr apper.java:515)
    org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 426)
    org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
    org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)

    root cause

    java.lang.NullP ointerException
    org.apache.jsp. myLogTest_jsp._ jspService(myLo gTest_jsp.java: 170)
    org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:70)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
    org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 384)
    org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
    org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
    What i can Do ? Pleas Help me ...... :)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by pravipravi
    [HTML]id=request.getP arameter("txtId ");
    51: pwd=request.get Parameter("txtP wd");
    52: rslogin=getAllD ata("select * from login where username='"+id+ "' and password='"+pwd +"'");
    53: while(rslogin.n ext())
    54: {
    55: flag=1;
    56: session.setAttr ibute("UserId", id); [/HTML]
    The above given is my coding.In my login table i have username and password.
    But when iam excecuing the application with Tomcat following error is occuring.

    org.apache.jasp er.JasperExcept ion: An exception occurred processing JSP page /myLogTest.jsp at line 53

    Stacktrace:
    org.apache.jasp er.servlet.JspS ervletWrapper.h andleJspExcepti on(JspServletWr apper.java:515)
    org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 426)
    org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
    org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)

    root cause

    java.lang.NullP ointerException
    org.apache.jsp. myLogTest_jsp._ jspService(myLo gTest_jsp.java: 170)
    org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:70)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
    org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 384)
    org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
    org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
    What i can Do ? Pleas Help me ...... :)
    Are there any situations where your getAllData method can return null?

    Comment

    • pravipravi
      New Member
      • Feb 2007
      • 16

      #3
      Originally posted by r035198x
      Are there any situations where your getAllData method can return null?
      This is the code i used.Here i declared rslogin as null.

      [HTML]<%
      String id="",pwd="",ar ea="";
      int flag=0;
      connectionMe();
      java.sql.Result Set rslogin=null;
      if(request.getP arameter("login hidden")!=null)
      {
      if(request.getP arameter("login hidden").equals ("login"))
      {
      id=request.getP arameter("txtId ");
      pwd=request.get Parameter("txtP wd");
      rslogin=getAllD ata("select * from login where username='"+id+ "' and password='"+pwd +"'");
      while(rslogin.n ext())
      {
      flag=1;
      // session.setAttr ibute("UserId", id);
      out.print("Logi n Successfully... .");
      // session.setAttr ibute("message" ,"");
      // redirect url
      response.sendRe direct("process .jsp");
      }
      if(flag==0)
      {
      session.setAttr ibute("message" ,"Invalid UserName or Password");
      }
      }

      }
      %>[/HTML]

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by pravipravi
        This is the code i used.Here i declared rslogin as null.

        [HTML]<%
        String id="",pwd="",ar ea="";
        int flag=0;
        connectionMe();
        java.sql.Result Set rslogin=null;
        if(request.getP arameter("login hidden")!=null)
        {
        if(request.getP arameter("login hidden").equals ("login"))
        {
        id=request.getP arameter("txtId ");
        pwd=request.get Parameter("txtP wd");
        rslogin=getAllD ata("select * from login where username='"+id+ "' and password='"+pwd +"'");
        while(rslogin.n ext())
        {
        flag=1;
        // session.setAttr ibute("UserId", id);
        out.print("Logi n Successfully... .");
        // session.setAttr ibute("message" ,"");
        // redirect url
        response.sendRe direct("process .jsp");
        }
        if(flag==0)
        {
        session.setAttr ibute("message" ,"Invalid UserName or Password");
        }
        }

        }
        %>[/HTML]
        The important line is this one

        Code:
         
        rslogin=getAllData("select * from login where username='"+id+"' and password='"+pwd+"'");
        Does the getAllData method return null?

        Comment

        • pravipravi
          New Member
          • Feb 2007
          • 16

          #5
          Originally posted by r035198x
          The important line is this one

          Code:
           
          rslogin=getAllData("select * from login where username='"+id+"' and password='"+pwd+"'");
          Does the getAllData method return null?

          This is my getAllData Function.

          Code:
          public java.sql.ResultSet getAllData(String sQuery)
            {
              java.sql.ResultSet rs=null;
            try
            {
           java.sql.Statement     state=conn.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_UPDATABLE);
           rs =state.executeQuery(sQuery);
            }catch(Exception e)
            {
               System.out.print(e.toString());
            }
             return rs;  
            }

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by pravipravi
            This is my getAllData Function.

            Code:
            public java.sql.ResultSet getAllData(String sQuery)
            {
            java.sql.ResultSet rs=null;
            try
            {
            java.sql.Statement state=conn.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_UPDATABLE);
            rs =state.executeQuery(sQuery);
            }catch(Exception e)
            {
            System.out.print(e.toString());
            }
            return rs; 
            }
            This is your problem

            Code:
             
            java.sql.Statement	 state=conn.createStatement(rs.TYPE_SCROLL_INSENSIT  IVE,rs.CONCUR_UPDATABLE);
            rs is still null at this point. You are calling static variables so use ResultSet (class name) instead of rs

            Comment

            • pravipravi
              New Member
              • Feb 2007
              • 16

              #7
              Originally posted by r035198x
              This is your problem

              Code:
               
              java.sql.Statement	 state=conn.createStatement(rs.TYPE_SCROLL_INSENSIT  IVE,rs.CONCUR_UPDATABLE);
              rs is still null at this point. You are calling static variables so use ResultSet (class name) instead of rs
              How to use the ResultSet(class name) in my coding?
              Or How can i make rs null?
              Actually i am using
              Code:
              public java.sql.ResultSet getAllData(String sQuery)
              {java.sql.ResultSet rs=null;
              
              }
              So there it self can rs be null?

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by pravipravi
                How to use the ResultSet(class name) in my coding?
                Or How can i make rs null?
                Actually i am using
                Code:
                public java.sql.ResultSet getAllData(String sQuery)
                {java.sql.ResultSet rs=null;
                 
                }
                So there it self can rs be null?

                Change the line

                Code:
                java.sql.Statement	 state=conn.createStatement(rs.TYPE_SCROLL_INSENSIT  IVE,rs.CONCUR_UPDATABLE);
                to

                Code:
                java.sql.Statement  state = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

                Comment

                • pravipravi
                  New Member
                  • Feb 2007
                  • 16

                  #9
                  Originally posted by r035198x
                  Change the line

                  Code:
                  java.sql.Statement	 state=conn.createStatement(rs.TYPE_SCROLL_INSENSIT  IVE,rs.CONCUR_UPDATABLE);
                  to

                  Code:
                  java.sql.Statement  state = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

                  I done the specified changes..But the Same error is coming again..
                  [HTML]org.apache.jasp er.JasperExcept ion: An exception occurred processing JSP page /myLogTest.jsp at line 53[/HTML]

                  Comment

                  • pravipravi
                    New Member
                    • Feb 2007
                    • 16

                    #10
                    I done the specified changes..But the Same error is coming again..


                    [HTML]org.apache.jasp er.JasperExcept ion: An exception occurred processing JSP page /myLogTest.jsp [/HTML]

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by pravipravi
                      I done the specified changes..But the Same error is coming again..


                      [HTML]org.apache.jasp er.JasperExcept ion: An exception occurred processing JSP page /myLogTest.jsp [/HTML]


                      Is the root cause still the nullpointer exception?
                      Which line is reported as giving the error now?

                      Comment

                      • pravipravi
                        New Member
                        • Feb 2007
                        • 16

                        #12
                        [HTML]50: id=request.getP arameter("txtId ");
                        51: pwd=request.get Parameter("txtP wd");
                        52: rs=getAllData(" select * from login where username='"+id+ "' and password='"+pwd +"'");
                        53: while(rs.next() )
                        54: {
                        55: flag=1;
                        56: // session.setAttr ibute("UserId", id);
                        [/HTML]

                        Stacktrace:
                        org.apache.jasp er.servlet.JspS ervletWrapper.h andleJspExcepti on(JspServletWr apper.java:515)
                        org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 426)
                        org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
                        org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
                        javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)

                        root cause

                        java.lang.NullP ointerException
                        org.apache.jsp. myLogTest_jsp._ jspService(myLo gTest_jsp.java: 170)
                        org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:70)
                        javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
                        org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 384)
                        org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
                        org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
                        javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
                        This is the Error report.Same line is showing the error.And,Root cause is null pointer exception.

                        Comment

                        • pravipravi
                          New Member
                          • Feb 2007
                          • 16

                          #13
                          Originally posted by pravipravi
                          [HTML]50: id=request.getP arameter("txtId ");
                          51: pwd=request.get Parameter("txtP wd");
                          52: rs=getAllData(" select * from login where username='"+id+ "' and password='"+pwd +"'");
                          53: while(rs.next() )
                          54: {
                          55: flag=1;
                          56: // session.setAttr ibute("UserId", id);
                          [/HTML]

                          Stacktrace:
                          org.apache.jasp er.servlet.JspS ervletWrapper.h andleJspExcepti on(JspServletWr apper.java:515)
                          org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 426)
                          org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
                          org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
                          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)

                          root cause

                          java.lang.NullP ointerException
                          org.apache.jsp. myLogTest_jsp._ jspService(myLo gTest_jsp.java: 170)
                          org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:70)
                          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
                          org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 384)
                          org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:320)
                          org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :266)
                          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
                          This is the Error report.Same line is showing the error.And,Root cause is null pointer exception.
                          yaa as above...

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Originally posted by pravipravi
                            [HTML]50: id=request.getP arameter("txtId ");
                            51: pwd=request.get Parameter("txtP wd");
                            52: rs=getAllData(" select * from login where username='"+id+ "' and password='"+pwd +"'");
                            53: while(rs.next() )
                            54: {
                            55: flag=1;
                            56: // session.setAttr ibute("UserId", id);
                            [/HTML]

                            .
                            That code throws a nullpointer only if the getAllData returns null. So you really need to be looking at your getAllData method.

                            Comment

                            • pravipravi
                              New Member
                              • Feb 2007
                              • 16

                              #15
                              Originally posted by r035198x
                              That code throws a nullpointer only if the getAllData returns null. So you really need to be looking at your getAllData method.
                              My entire business logic progran i am giving below.
                              Code:
                              <%@ page import= "java.sql.*" %>
                              <html>
                              <head>
                              <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
                              <title>
                              </title>
                              </head>
                              <body>
                              <%
                              %>
                              <%!
                              public Connection conn;
                              public void connectionMe()
                              {
                              try
                                {
                              conn=java.sql.DriverManager.getConnection("jdbc:oracle:thin:slippage/slippage@172.18.1.92:1521:orcl");  
                                 }catch(Exception e)
                                 {
                                   System.out.print("error");
                                 }
                              }
                              public java.sql.ResultSet getAllData(String sQuery)
                                {
                                  java.sql.ResultSet rs=null;
                                try
                                {
                               //rs.TYPE_SCROLL_SENSITIVE,rs.CONCUR_UPDATABLE
                               java.sql.Statement  state=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                                   rs =state.executeQuery(sQuery);
                                }catch(Exception e)
                                {
                                   System.out.print(e.toString());
                                }
                                 return rs;  
                                }  
                              
                              public void executeQuery(String sQuery) throws Exception
                              {
                              try{
                                 java.sql.Statement insquery =conn.createStatement();
                                 insquery.executeUpdate(sQuery);
                                 insquery.close();
                              }catch(Exception e)
                              {
                                  throw new Exception(e.toString());
                              }
                              }
                              
                              %>
                              </body>
                              </html>
                              Here where is a mistake that i am not getting...

                              Comment

                              Working...