jsp, store values from database.

Hi everyone,

I have a table in a database in microsoft Access and this table has a column which has two rows:

Price (name of column)

32

4

what I want is that each number, in this case:

32 and 4

gets stored in a respectively variable for each number,

for example:

2 in a variable like: String a;

59 in a variable like: String bt;

so each number will have it's own variable.

this is what i've tried, but it's not working.

while(resultset.next()){

for (int i=1; i<=1; i++){

pre2=resultset.getString(i);

}

String REGEX ="";

java.util.regex.Pattern p = java.util.regex.Pattern.compile(REGEX);

String[] arr =new String[2];

arr = p.split(pre2);

out.println(arr[1]);

}

I was thinking in storing the values by storing a given position of the array in a variable like this:

String pgf = arr[1];

but,

I put the line out.println(arr[1]);

, just to test/see if it was printing the second row, in this case: 4,

but it's not doing that,

what is printing right now is the first number of the first row, and the first number of the second row: 34

what can i do to solve this?

thanks...

[1533 byte] By [deroka] at [2007-11-27 8:47:15]
# 1
.
deroka at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> Hi everyone,

> I have a table in a database in microsoft Access and

> this table has a column which has two rows:

>

> Price (name of column)

>

> 32

> 4

>

> what I want is that each number, in this case:

> 32 and 4

> gets stored in a respectively variable for each

> number,

> for example:

>

> 2 in a variable like: String a;

> 59 in a variable like: String bt;

>

> so each number will have it's own variable.

>

> this is what i've tried, but it's not working.

>

> while(resultset.next()){

//gets the individual rows

>for (int i=1; i<=1; i++) {

//get the 1st element from the row as i =1

> e2=resultset.getString(i);

>}

> ing REGEX = "";

> java.util.regex.Pattern p =

> java.util.regex.Pattern.compile(REGEX);

>String[] arr = new String[2];

> arr = p.split(pre2);

> arr[1]);

> }

>

Please look at my comments inlined in the code u had given

I am not able to make out what u need from the info u provided!!

vinayak_ra at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> Please look at my comments inlined in the code u had

> given

> I am not able to make out what u need from the info

> u provided!!

the code i posted is not the best way to explain it, cause it's not doing what is suppoused to do. sorry for that.

I'll explain it in words:

what I want is to store each row value,in a variable.

for example:

(a column in a database)

LastName(name of column)

>

> Smith

> Johnson.

so in the jsp i would like to store the lastnames in variables.

Smith in a variable like: String a;

Johnson in a variable like: String bt;

how can i do that?

deroka at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Why would you want to do that actually?
Nidhuggura at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
> Why would you want to do that actually?because i need to work with each value separately,it's something i need to do so my program can work.
deroka at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Here u go!!!!!

String [] lastName = new String[5]; //remove hardcoding

int i=1;

while(resultset.next()){

//gets the individual rows

>

> lastName[i-1]=resultset.getString(i);

> i++

> }

String a= lastName[0];

String b=lastName[1];

.......................................... ....... ....

vinayak_ra at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
thanks a lot vinayak_r!!!
deroka at 2007-7-12 20:51:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...