This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector for database query

 
nikhil govind
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could not understand your question, could you please post your code. I will see if I can help.
 
rohit chavan
Ranch Hand
Posts: 132
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use proper formatting while posting your code. Use the code tag so that it helps other members to understand your question.
 
John Jai
Rancher
Posts: 1776
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid Vector and use List collection if you don't need to handle concurrency.
 
Winston Gutkowski
Bartender
Pie
Posts: 9484
50
Eclipse IDE Hibernate Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 9484
50
Eclipse IDE Hibernate Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I havent been able to understand the query of the OP.
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did concurrency step in? Why is everyone assuming here? It may be that nikhil is learning Vectors!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47286
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can still buy books telling you to use StringTokenizer, Vector, Hashtable and Enumeration.
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47286
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic