aspose file tools*
The moose likes Beginning Java and the fly likes Vector for database query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector for database query" Watch "Vector for database query" New topic
Author

Vector for database query

nikhil govind
Ranch Hand

Joined: Mar 08, 2011
Posts: 31
hi to all,

I have created a vector to store the database query results using "dataset" syntax like getDataset etc.
now when i print using logger the format is [[values],[values]]
again to retrieve element by element value i created another vector vectorname2 and used vecotrname.elementAt() which gives the result in [values] form.
Now for null value of database i entered a check and used vectorname2.add(count,"some words")...what happens is it gets inserted at that place
row = (Vector) rows.elementAt(count); --> a single elemet is present each time in this method
but
row.add(0,"no drive or test center"); inserts a new value at 0th position after every iteration making its size increase...

so my doubt is how to get only one element as in case -- > row = (Vector) rows.elementAt(count); even if i have to add a new element after check?
is there any syntax to do it ?
Premkumar Karnan
Greenhorn

Joined: May 04, 2007
Posts: 2
I could not understand your question, could you please post your code. I will see if I can help.
rohit chavan
Ranch Hand

Joined: Oct 08, 2010
Posts: 132

Please use proper formatting while posting your code. Use the code tag so that it helps other members to understand your question.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Please avoid Vector and use List collection if you don't need to handle concurrency.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

nikhil govind wrote:I have created a vector to store the database query results using "dataset" syntax like getDataset etc.

Why? Isn't a ResultSet good enough? Or are you not using JDBC? The only 'getDataSet' function I can find seems to be related to .NET or ASPs.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Sometimes you need the data for longer periods of time (e.g. in a user interface), and you don't want to keep the ResultSet open the entire time.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Rob Spoor wrote:Sometimes you need the data for longer periods of time (e.g. in a user interface), and you don't want to keep the ResultSet open the entire time.

Fair enough, but it seems to me that the thing to do then is to convert it to POJOs (but maybe, as John says, a List rather then a Vector). Swapping one type of matrix for another doesn't add a lot of value to me.

Winston
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

I think I havent been able to understand the query of the OP.

Mohamed Sanaulla | My Blog
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Mohamed Sanaulla wrote:I think I havent been able to understand the query of the OP.

Nor do I... Not able to get what he is trying to achieve...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Winston Gutkowski wrote:
Rob Spoor wrote:Sometimes you need the data for longer periods of time (e.g. in a user interface), and you don't want to keep the ResultSet open the entire time.

Fair enough, but it seems to me that the thing to do then is to convert it to POJOs (but maybe, as John says, a List rather then a Vector). Swapping one type of matrix for another doesn't add a lot of value to me.

Winston

I couldn't agree with you more on that one.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

John Jai wrote:Please avoid Vector and use List collection if you don't need to handle concurrency.


And even if you do need to handle concurrency, don't use Vector. Only use it if you have to interact with Legacy code that requires it.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Where did concurrency step in? Why is everyone assuming here? It may be that nikhil is learning Vectors!


===Vyas Sanzgiri===
My Blog
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vyas Sanzgiri wrote:Where did concurrency step in?


That will be clear if you read the thread.

Why is everyone assuming here?


I don't think anybody is assuming anything.

It may be that nikhil is learning Vectors!


It seems very unlikely that that is the real goal here. And if it is, he should be dissuaded from spending time on Vectors and encouraged to learn things like Collection, List, ArrayList, and Iterator.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39395
    
  28
You can still buy books telling you to use StringTokenizer, Vector, Hashtable and Enumeration.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Vyas Sanzgiri wrote:Where did concurrency step in? Why is everyone assuming here? It may be that nikhil is learning Vectors!


Yes... quite likely he is living in a place where it's still 2002.
nikhil govind
Ranch Hand

Joined: Mar 08, 2011
Posts: 31
agreed its a old method...but am new to all these...so was trying...
i had filled the vector 1 with data set from database....now the value was to be printed so "get Element at" works if there is an element and in case of null value it throws exception
so i wanted some dummy element to be added so i used add method of vector adding a string but it again throws exception java language exception as its not an vector element object that gets added but a string value
so i stored it first in one vector then added that vector and it started working fine
all research done by myself .....
so right now problem resolved thanks for the help you all had written out here i will keep these points in mind....

happy coding :-)
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Jeff Verdegan wrote:
Vyas Sanzgiri wrote:Where did concurrency step in?


That will be clear if you read the thread.

Why is everyone assuming here?


I don't think anybody is assuming anything.

It may be that nikhil is learning Vectors!


It seems very unlikely that that is the real goal here. And if it is, he should be dissuaded from spending time on Vectors and encouraged to learn things like Collection, List, ArrayList, and Iterator.


Care to explain?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vyas Sanzgiri wrote:
Jeff Verdegan wrote:
Vyas Sanzgiri wrote:Where did concurrency step in?


That will be clear if you read the thread.

Why is everyone assuming here?


I don't think anybody is assuming anything.

It may be that nikhil is learning Vectors!


It seems very unlikely that that is the real goal here. And if it is, he should be dissuaded from spending time on Vectors and encouraged to learn things like Collection, List, ArrayList, and Iterator.


Care to explain?


Explain what?
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Jeff Verdegan wrote:
Vyas Sanzgiri wrote:
Jeff Verdegan wrote:
Vyas Sanzgiri wrote:Where did concurrency step in?


That will be clear if you read the thread.

Why is everyone assuming here?


I don't think anybody is assuming anything.

It may be that nikhil is learning Vectors!


It seems very unlikely that that is the real goal here. And if it is, he should be dissuaded from spending time on Vectors and encouraged to learn things like Collection, List, ArrayList, and Iterator.


Care to explain?


Explain what?


1. "I don't think anybody is assuming anything."
2. "dissuaded from spending time on Vectors"

PS: I read every post esp the OP before I post [Another assumption ? ]



Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

The idea is not only to help solving problems or issues but also to provide some valuable advice from people who have been well versed in the field. So people pitch in with suggestions for improving the coding style or may be provide some gotchas related to some concepts.

There are few things when used, people pitch in to correct and suggest alternatives- for example StringTokenizer.

(Again we all try to see to it that we dont deviate a lot from the OP's original question).
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vyas Sanzgiri wrote:
Care to explain?

Explain what?


1. "I don't think anybody is assuming anything."
2. "dissuaded from spending time on Vectors"

PS: I read every post esp the OP before I post [Another assumption ? ]



You can PM me if you wish, so that we don't clutter this thread any further.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39395
    
  28
Vyas Sanzgiri, I think you are making this thread more confused than it need be.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector for database query