Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with JDBC

 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am having a Java File which uses JDBC. I am using Vectors to access the resultset. My code is working fine if i want to access a single column. But to access all the columns with same Vector, is it possible. I want your suggesstions. Your help is very much appreciated.

Regards,
Raghu
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post what error are you getting or can you be more clear.
 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghu,
Do you have a one-dimensional or two-dimensional Vector?
 
Kash Mhai
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic