This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Array storing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array storing" Watch "Array storing" New topic
Author

Array storing

Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Aug 10, 2005
Posts: 685
.. 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

Joined: Sep 06, 2004
Posts: 15
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


I am not completely useless.<br />I can be used as a bad example.<br /> <br />SCJP 1.4
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3160
    
  10
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.


Joanne
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array storing
 
Similar Threads
Stateful Session Bean - Conversational State
Starting to open the connection at the beginning of the class
use c:forEach tag inside another c:forEach tag
Objects in JSP
Storing of Data