0

Hi!,
when im trying to execute following code.i get this error.can any one help me to make it correct.

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at SelectApp.main(SelectApp.java:18)

this is my code.

import java.sql.*;
 
public class SelectApp {
  public static void main(String args[]) {
  String ss="Italiantomato";
  
 
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch( Exception e ) {
      System.out.println("Failed to load mSQL driver.");
      return;
    }
    try {
      Connection con = DriverManager.getConnection("jdbc:odbc:test1","","");
      Statement select = con.createStatement();
      ResultSet result = select.executeQuery("select price from Item_size where item_code = '3' and size = 's' ");   


 
      System.out.println("Got results:");
      while(result.next()) { // process results one row at a time
        Long key = result.getLong(1);
        
 
        System.out.println("key = " + key);
       
      }
      select.close();
      con.close();
    }
    catch( Exception e ) {
      e.printStackTrace();
    }
  }
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by java_programmer
0

Check the datatype of item_code and size fields in your table.
According to sql, they should be of type String, but in the table their datatypes are something different, which I guess based on your code snippet and error message.

Hi!,
when im trying to execute following code.i get this error.can any one help me to make it correct.

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at SelectApp.main(SelectApp.java:18)

this is my code.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.