Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Array storing

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to use an array to store the item from database instead of hard coding the item which is shown at the last part of the code.
When i do a System.out.println(itemName + serialNumber+ carModel + listPrice); , it did show the item from database but when i use an array to store it, it does not show the correct output.WHY???


while (rs.next()) {
for (int i = 1; i <= info.getColumnCount(); i++) {
itemName = rs.getString("itemName");
serialNumber = rs.getString("serialNumber");
carModel = rs.getString("carModel");
listPrice = rs.getDouble("listPrice");

items[i]=new Item(itemName, serialNumber,carModel, listPrice);
System.err.println(items[i]);

}



// private static Item[] items =
// { new Item(itemName,
// "<I>"+carModel+"</I> ",
// specifications,44.44),
//
// new Item("11111",
// "Description","This is a decription",49.95)
// };
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may be wrong but I don't see how this is a Servlet question.
Moving to Java in General (beginner).
 
Rancher
Posts: 4739
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

.. it does not show the correct output.WHY???



What does it display? Could you post the output here?
What is wrong with what it displays? Could you explain that and describe what it should have output?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Nico Yukiko ,
What is the reference type of ur array. btw an array is a collection of same objects. how can u put an double and string in the same array. try rectifying this problem and see how it works.

Unqualified Genius
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a guess, I would say you need to override your Item class's toString() method to output the data in the form you require.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Norm Radder:


What does it display? Could you post the output here?
What is wrong with what it displays? Could you explain that and describe what it should have output?



I agree with Norm. Please show us what the above code displays so that we can help you fix it.

Layne
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic