我正在访问数据库中搜索项目代码并返回项目对象,如下面的代码所示。任何关于我为什么会收到此错误的建议将不胜感激。谢谢
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)