>From this statement
                         int idT = rs.getInt("Id");
I take that column Id is an integer.  If that is the case, then you
shouldn't use the following statement
             Statement statement1 = connection.createStatement();
                         String query1 = "SELECT Password FROM Details " +
                                                        "WHERE Id = ' " + id
+ "'";
because you resulting statement1 will be something like
        SELECT Password FROM Details WHERE Id = '5'
I think that is the reason that you got the SQL Data Mismatch.

Either you shouldn't call getInt, or you shouldn't put ' characters in your
query1.

Hope this helps.

Shane

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Jennifer Feeney
Sent: Tuesday, February 06, 2001 4:59 PM
To: [EMAIL PROTECTED]
Subject: Problem using Servlets for User Authentication


Hi all,

I have run into a problem and would really appreciate any help on it.

Thank you, in advance to anyone that may be able to help......

Description:
----------------------------------------------------------------------
-----
I have developed a Login Page, which is a servlet.....
it has two fields.....Id and Password.

The user fills in both fields and presses the submit button, which in
turn
invokes another servlet "LoginServlet".......

Up to here everything works fine.
My LoginServlet, opens a connection to my database, retrieves info
 from appropriate fields (Id and Password info) and then goes on to
compare the info retrieved from database to the info(Id and Password)
entered by the
user.....

If both pieces of info compare correctly, the user is sent back a
welcome
message......
If the password does not match, a message informing the user of this
is sent
back and finally, if the Id does not match, a message of this is sent
to the
user informing them of this.....

So thats what supposed to happen.....

Problem:
----------------------------------------------------------------------
------
When i press the submit button, all I get is a blank page, the
LoginServlet
displays nothing on the screen, and I am getting
a "java.sql.SQLEXCEPTION: Data Mismatch in Criteria
Expression"...message.

I have gone through this time and again, and cannot seem to find the
solution to it.....
Below is the code listing for what I have explained above.............


Code:
----------------------------------------------------------------------
----



public void doPost( HttpServletRequest req,
                       HttpServletResponse res )
      throws ServletException, IOException
   {
      String password ,id;

      id = req.getParameter("IdNo");
      password = req.getParameter( "Password" );


      PrintWriter output = res.getWriter();
      res.setContentType( "text/html" );

      if (id.equals( "" ) ||
           password.equals( "" )) {
         output.println( "<H3> Please click the back " +
                         "button and fill in all " +
                         "fields.</H3>" );

         output.close();
         return;
       }



                 try{

                         Statement statement =
connection.createStatement();
                         String query = "SELECT Id FROM Details " +
                                                        "WHERE
Password = '" + password + "'";
             Statement statement1 = connection.createStatement();
                         String query1 = "SELECT Password FROM
Details " +
                                                        "WHERE Id
= ' " + id + "'";

                         ResultSet rs = statement.executeQuery(
query );
                         rs.next();
                         int idT = rs.getInt("Id");


                         ResultSet rs1 = statement1.executeQuery(
query1 );
                         rs1.next();
                         String passwordT = rs1.getString("Password");

                         int x = passwordT.compareTo(password);
                         int y = Integer.parseInt(id);


                                if(x == 0 && idT == y){

                                output.println( "<H1><Font
color:Red>Welcome to our Online Service!</FONT><BR></H1>");
                        output.println(getServletInfo());

                        }

                        if(x > 0 ){
                                 output.println( "<H1><Font
color:Red>Incorrect Password!</FONT><BR></H1>");
                                output.println( "<BR><BR><H1><Font
color:Blue>Please click the, Back, button and try again!
</FONT><BR></H1>");
                        }

                        if(idT != y){
                                output.println( "<H1><Font
color:Red>Incorrect Id Entered!</FONT><BR></H1>");
                                output.println( "<BR><BR><H1><Font
color:Blue>Please click the, Back, button and try again!
</FONT><BR></H1>");
                        }


                     statement.close();
                     statement1.close();
              }


             catch ( SQLException sqlex ){ //catch any exceptin that
may occur as a result of try
             sqlex.printStackTrace();
             //output.append( sqlex.toString() );
         }

      output.close();//close output

   }

CODE END:
----------------------------------------------------------------------
----------------------------

Any help would be GREATLY appreciated, as always.

Kind Regards,
Jennifer

_____________________________________

Get your free E-mail at http://www.ireland.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to