Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing value from database to an array

 
suraya ya'acob
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've got a problem to pass values from database to an array.
I retrieved values from the database using while (rs.next()), then I want to pass all the values to an array.
The problem is I will get the looping array that depends on the values i've got from database. Let say i've got 10 values then i will get 10 arrays and only index 0 each array contain value.
please help me.
here is my coding sample.
********************
database
year
1999
2000
2001
2002
2003
****************main class*************

*************arr class*********

[ September 30, 2003: Message edited by: Gregg Bolinger ]
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see a couple of problems. First, this is not the syntax for assignment:

You are actually comparing the value of pixel to the literal 30.
Second, do you ever set the value of year?
Third, look into the syntax of the case statement. It will clean up those repetitive if's.
Last, what should the end result of this run be? As it is now, every iteration of the while() statement overwrites the last assignment of arr a1, so when you are finished you will only have the latest instance of arr. Maybe you should look into ArrayList to store all the values you get out of the db.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing that will help us it using UBB Code tags to format your code.
I have edited your post to include these tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic