Raghuraman Muthuswamy
Ranch Hand
Posts: 73
posted 13 years ago
Dear Srini,
The problem is i have 4 columns. Iam using getString and getInt methods whichever is appropriate to get the values from the Database. Then i use addElement method of Vectors to populate the vector. when i populate all the columns into the Vector, all columns seem to be merged. That is i have prodid,Name,price and Quantity. the result of the vecotor is 10,Raghu,20,50 and for the next record 20,Kumar,25,30. I want to have the appropriate columns to be displayed in a sequence. That is Prodid 10 20 then name Raghu Kumar like that. How to do that. Your reply is much appreciated.
Thanks in advance,
Raghu
The problem is i have 4 columns. Iam using getString and getInt methods whichever is appropriate to get the values from the Database. Then i use addElement method of Vectors to populate the vector. when i populate all the columns into the Vector, all columns seem to be merged. That is i have prodid,Name,price and Quantity. the result of the vecotor is 10,Raghu,20,50 and for the next record 20,Kumar,25,30. I want to have the appropriate columns to be displayed in a sequence. That is Prodid 10 20 then name Raghu Kumar like that. How to do that. Your reply is much appreciated.
Thanks in advance,
Raghu
posted 13 years ago
Raghu,
Do you have a one-dimensional or two-dimensional Vector?
Do you have a one-dimensional or two-dimensional Vector?
[OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
posted 13 years ago
You could use ResultSetMetaData to findout how many columns you have.
Once you have the no. of columns, you could add all results to your vector.
Divide the no. of elements of vector by the no. of columns you have to get the no. of rows you have. this should give the no. of rows. If the no. of columns is fixed, say 4; then using the following might solve your prob,
int i=0;
while (i<vec.size())
{
strCol1 = vec.get(i++);
strCol2 = vec.get(i++);
strCol3 = vec.get(i++);
strCol4 = vec.get(i++);
}
Cheers!
Once you have the no. of columns, you could add all results to your vector.
Divide the no. of elements of vector by the no. of columns you have to get the no. of rows you have. this should give the no. of rows. If the no. of columns is fixed, say 4; then using the following might solve your prob,
int i=0;
while (i<vec.size())
{
strCol1 = vec.get(i++);
strCol2 = vec.get(i++);
strCol3 = vec.get(i++);
strCol4 = vec.get(i++);
}
Cheers!
-------------<br />There are wheels within wheels...<br />P.G Wodehouse

it's a teeny, tiny, wafer thin ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|