Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with JDBC

 
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
 
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
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghu,
Do you have a one-dimensional or two-dimensional Vector?
 
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!
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic