java.sql.SQLException:[Microsoft][ODBC Excel驱动程序]条件表达式中的数据类型不匹配。错误

java.sql.SQLException:[Microsoft][ODBC Excel驱动程序]条件表达式中的数据类型不匹配。错误,java,excel,Java,Excel,我在执行程序时遇到了这个错误 SQL查询是:从[sheet1$]中选择标题、价格、数量 所选记录包括: aa,22.0,22 记录总数=1 java.sql.SQLException: [Microsoft][ODBC Excel Driver] Data type mismatch in criteria expression. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.od

我在执行程序时遇到了这个错误 SQL查询是:从[sheet1$]中选择标题、价格、数量 所选记录包括: aa,22.0,22 记录总数=1

java.sql.SQLException: [Microsoft][ODBC Excel 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.executeUpdate(Unknown Source)
    at package1.currentTime.main(currentTime.java:48)
我将插入步骤更改为插入[Sheet1$]标题、价格、数量值'title'、'firstName'、'999'; 但同样的错误 有什么建议吗

package package1;
import java.sql.*;

public class currentTime {  // JDK 7 and above
    static Connection con;
    static Statement st;
    ResultSet rs;
   public static void main(String[] args) {
      try (
         // Step 1: Allocate a database "Connection" object
         Connection conn = DriverManager.getConnection(
               "jdbc:odbc:final");  // Access/Excel

         // Step 2: Allocate a "Statement" object in the Connection
         Statement st = conn.createStatement();
      ) {
         // Excel connection, by default, is read-only.
         // Need to turn it off to issue INSERT, UPDATE, ...
         conn.setReadOnly(false);

         // Step 3: Execute a SQL SELECT query, the query result
         //   is returned in a "ResultSet" object.
         // Table name is the sheet's name in the form of [sheet-name$]
         String strSelect = "select title, price, qty from [sheet1$]";
         System.out.println("The SQL query is: " + strSelect); // Echo For debugging

         ResultSet rs = st.executeQuery(strSelect);

         // Step 4: Process the ResultSet by scrolling the cursor forward via next().
         //  For each row, retrieve the contents of the cells with getXxx(columnName).
         System.out.println("The records selected are:");
         int rowCount = 0;
         while(rs.next()) {   // Move the cursor to the next row
            String title = rs.getString("title");
            double price = rs.getDouble("price");
            int    qty   = rs.getInt("qty");
            System.out.println(title + ", " + price + ", " + qty);
            ++rowCount;
         }
         System.out.println("Total number of records = " + rowCount);


         int returnCode = st.executeUpdate(

            "insert into [Sheet1$] (title, price, qty) values ('" + "title" + "','" + "firstName" + "','" + 999 + "')");
         System.out.println(returnCode + " record(s) inserted.");

         // Try UPDATE
         returnCode = st.executeUpdate(
            "update [sheet1$] set qty = qty+1 where id = 1002");
         System.out.println(returnCode + " record(s) updated.");

      } catch(SQLException ex) {
         ex.printStackTrace();
      }
      // Step 5: Close the resources - Done automatically by try-with-resources
   }
}

请检查您的查询和字段的数据类型。从您的查询中,看起来您正在传递一个字符串值,其中需要一个整数值

在[Sheet1$]中插入标题、价格、数量值“title”、“firstName”、“999”


根据您的查询,sit似乎不是字符串,但您正在将“firstName”作为一个值传递给它。

价格列不是字符串,为什么您试图在名为price的列中插入值“firstName”?很抱歉,我写了您的建议,我出错了程序不接受您的建议标题下的红线“,”firstName“,”999”