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();
    }
  }
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.