我正在用下面的代碼查詢Microsoft Access數據庫。數據庫字段名稱在SELECT語句中正確聲明。試圖找出爲什麼我得到這個錯誤。真的需要一些help..thanksjava.sql.SQLException:未找到列錯誤?
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)
編輯:的字段是相同的,這裏有一個屏幕截圖
你能檢查數據庫中列名的大小寫與你指定的大小寫是否完全一致嗎? – Igor
yup ..這些字段是相同的,請參閱屏幕截圖 – Adesh
您是否調試過並看到天氣有任何結果?或者結果集是空的? – andunslg