Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array storing

 
Nico Yukiko
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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)
// };
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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).
 
Norm Radder
Ranch Hand
Posts: 882
6
  • Mark post as helpful
  • send pies
  • 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?
 
Anoop Kavalloor
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • 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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic