gpt4 book ai didi

java - SQLException : [Microsoft][ODBC Microsoft Access Driver] Too few parameters. 应为 1

转载 作者:行者123 更新时间:2023-11-29 05:52:45 25 4
gpt4 key购买 nike

我正在 access 数据库中搜索项目代码并返回项目对象,如下面的代码所示。任何关于我为什么会收到此错误的建议都将不胜感激。谢谢

public Item getIteminfo(String itemCode) throws ClassNotFoundException, SQLException {
Statement myStatement = getConnection();
Item item = null;
String itemDescription;
int itemPrice;
String sql = "SELECT * FROM itemCatalog WHERE ItemCode = '"+itemCode+"'";
ResultSet results = myStatement.executeQuery(sql);

while (results.next()){
itemDescription = results.getString("Item Description");
itemPrice = results.getInt("Item Price");
item = new Item(itemDescription, itemPrice);
}
closeConnection();
return item;
}
}

这是错误的详细信息:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3109)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:252)
at checkoutsimulation.DAO.getIteminfo(DAO.java:49)
at checkoutsimulation.ItemCatalog.getItemdetails(ItemCatalog.java:61)

最佳答案

我对 Java 或 ODBC 不是很熟悉,但我知道数据库不接受带有空格的列名。

尝试将列名称括在方括号中。

itemDescription = results.getString("[项目描述]");

关于java - SQLException : [Microsoft][ODBC Microsoft Access Driver] Too few parameters. 应为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13300876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com