I am querying an Microsoft Access database with the code below. The database field names are correctly stated in the SELECT statement. Trying to figure out why I am getting this error. Really need some help..thanks
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;
}
Here's the error message:
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)
Edited: The fields are identical, here's a screen shot

I don't have access myself so I cannot try this, but here is something that might work. First we print out the names of the columns in the result set in case there is some case sensitivity at work.
Then we do a workaround int the result.next loop using positional arguments (1, 2, ..) instead of names. This should make it work regardless of what the names are.
Once you figure out what the name problem is, replace the 1, 2 etc with the correct names.