0

I have an ArrayList itemNameList. It is supposed to contain many different ITEM_NAME which I get them from a database.

On the code shown above i try to allocate the items of an order to the corresponding ORDER_ID. This means I need to access the ITEM_NAME column many times for only one ORDER_ID. (arrayOrdersId contains all the ORDER_ID).

When I try to display the content instead of getting the item names I get something that looks like a memory address.

Thanks in advance

st = conn.createStatement();
        rs = st.executeQuery("SELECT ITEM_NAME FROM ORDER_DETAIL WHERE ORDER_ID =  " + arrayOrdersId[rowIndex]);          

        orderIdList.add(arrayOrdersId[rowIndex]);

        Item itemName;

        while(rs.next())
        {
            itemName = new Item(rs.getString("ITEM_NAME"));

            itemNameList.add(itemName);
        }
  • And how are you displaying the content? – user253751 May 04 '17 at 00:22
  • it is not address. it is default implementation of toString – jmj May 04 '17 at 00:23
  • suppose you just put `System.out.println(rs.getString("ITEM_NAME"));`and see you are getting a value. – Rajith Pemabandu May 04 '17 at 00:27
  • They are correct, you are probably looping over your itemNameList and just System.out.print-ing each value. It uses the default toString() method from class Object(which is not very friendly looking). Either override the toString() method in ItemName class or get the name variable from that class to print. – javaBean007 May 04 '17 at 00:37

0 Answers0