我正在使用下面的代码查询 Microsoft Access 数据库。SELECT 语句中正确说明了数据库字段名称。试图弄清楚为什么我会收到这个错误。真的需要一些帮助..谢谢
public Item getIteminfo(String itemCode) throws ClassNotFoundException, SQLException {
Statement myStatement = getConnection();
Item item = null;
String itemDescription;
int itemPrice;
String sql = "SELECT ItemDescription, ItemPrice FROM itemCatalog WHERE ItemCode = '"+itemCode+"'";
ResultSet results = myStatement.executeQuery(sql);
while (results.next()){
itemDescription = results.getString("ItemDescription");
itemPrice = results.getInt("ItemPrice");
item = new Item(itemDescription, itemPrice);
}
closeConnection();
return item;
}
这是错误消息:
java.sql.SQLException: Column not found
at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(JdbcOdbcResultSet.java:1849)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:410)
at checkoutsimulation.DAO.getIteminfo(DAO.java:52)
at checkoutsimulation.ItemCatalog.getItemdetails(ItemCatalog.java:61)
at checkoutsimulation.CheckoutSystem.bnPurchaseActionPerformed(CheckoutSystem.java:463)
at checkoutsimulation.CheckoutSystem.access$100(CheckoutSystem.java:20)
已编辑:字段相同,这是屏幕截图