-
[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("jdbc dbc: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
-
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
-
By rdwagco2 in forum Database
Replies: 5
Last Post: 08-03-2005, 09:44 AM
-
Replies: 2
Last Post: 06-27-2003, 12:06 PM
-
By chiradip das in forum Careers
Replies: 0
Last Post: 02-14-2003, 10:41 AM
-
By chiradip das chiradip_rediffmail.com in forum Careers
Replies: 0
Last Post: 02-14-2003, 10:39 AM
-
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
Forum Rules
|
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
|
Bookmarks