[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
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
out.println("The user ID is a required field"); %> <br> <%
out.println("The password is a required field");
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)
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 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.
By rdwagco2 in forum Database
Last Post: 08-03-2005, 09:44 AM
Last Post: 06-27-2003, 12:06 PM
By chiradip das in forum Careers
Last Post: 02-14-2003, 10:41 AM
By chiradip das chiradip_rediffmail.com in forum Careers
Last Post: 02-14-2003, 10:39 AM
Last Post: 10-11-2002, 10:52 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL