[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

  1. #1
    Join Date
    Sep 2005
    Posts
    39

    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    Hey guys/gals,

    I am getting the above error message with the following code:

    session = pageContext.getSession();

    boolean connectedToDatabase = false;
    boolean login = false;

    String userID = request.getParameter("userID");
    String password = request.getParameter("password");


    //validating userID for null
    if((userID.equals(""))||(password.equals("")))
    {
    out.println("The user ID is a required field"); %> <br> <%
    out.println("The password is a required field");
    }
    else
    {

    Connection con;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    con = DriverManager.getConnection("jdbcdbc:laGuardia","","");

    connectedToDatabase = true;

    String sql = "SELECT insurer.insurerID, insurer.password, occupation.OccupationID "
    +"FROM occupation , insurer where occupation.OccupationID='2' AND insurer.password = "+password+" AND insurer.insurerID = "+userID+";";

    login = true;

    Statement stmt =con.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    }// end try

    catch (SQLException e)
    {
    out.println(e.getMessage());
    }// out.println

    if (! connectedToDatabase)
    throw new IllegalStateException ("You are not connected to the database");

    if (! login)
    out.println ("You have entered an invalid User ID or password");


    %>

    UserID and password are coming in as variables from another page, but they are coming in as String data types. If I convert them with an Integer.parseInt(variable), I get a different error message.

    I am entering the correct parameters in the userID and password columns, any suggestions on what I may be doing wrong?

    Maria

  2. #2
    Join Date
    Aug 2005
    Posts
    24

    Smile Maria Modeste's SQL Statement

    Ok Maria first of all you have to specify the types of your fields. The only thing wrong with your SQL statement is

    > String sql = "SELECT insurer.insurerID, insurer.password,
    > occupation.OccupationID "
    > +"FROM occupation , insurer where occupation.OccupationID='2' AND
    > insurer.password = "+password+" AND insurer.insurerID = "+userID+";"; "

    occupation.OccupationID = '2' .
    If the above parameter is a string, than its fine but if the above parameter is an integer, you have to use Integer.parseInt(X) to parse it to an integer and concatinate it with out using the ' x ' single quotes. The second thing is ( it might be ) that you do not have to use ";" in the end. Check your database column types and also post the other exception that you are getting when parsing it to an integer.
    read your code carefully and try. reply if it does not work.

Similar Threads

  1. Data type mismatch using date() function
    By rdwagco2 in forum Database
    Replies: 5
    Last Post: 08-03-2005, 09:44 AM
  2. Replies: 2
    Last Post: 06-27-2003, 12:06 PM
  3. Replies: 0
    Last Post: 02-14-2003, 10:41 AM
  4. undertakes any type of data entry (microsoft based software)
    By chiradip das chiradip_rediffmail.com in forum Careers
    Replies: 0
    Last Post: 02-14-2003, 10:39 AM
  5. Replies: 0
    Last Post: 10-11-2002, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center