Comparing values !!!

hi all,

Friends !!!

1]I have a string which have values seperated by delimiter ",", i have split the string and stored it into the vector. For example str2="jsp,servlet,hibernate";

there is another string having value stored into the database. and for fetching this value from the database.

i have a table name valuetable which have column1,column2, column3 all the 3 column have value in ss1,ss2,ss3.....ssn format.

now i have to compare the value of column1 for example have value="jsp,java,weblogic,struts" . If at least one value matches from the string then the value of that all the columes of particular row of the table should be fetched.

So how should i do this help me.

2] now it may happen that for my condition if i get 20 rows selected then how will i mange to compare this much lots of data with the particular column name for each row with the string str2 above given.

[932 byte] By [java@mania] at [2007-11-27 10:56:47]
# 1

put the comma delimited values in the ArrayList.

Use ArrayList contrains method.

boolean java.util.ArrayList.contains(Object elem)

Returns true if this list contains the specified element.

skp71a at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

String values = "bar,foo,meep,rofl";

String inputs = "foo,fake,meep,copter";

List<String> valueList = Arrays.asList(values.split(","));

List<String> inputList = Arrays.asList(inputs.split(","));

for (String input : inputList) {

if (valueList.contains(input)) {

System.out.println("Matched: " + input);

}

}

BalusCa at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

hi Balus C,

I got how to compare using the the contain method.so my first problem is solved.Taking simple variables,as u said to play with them.

But my 2nd problem says how i want to take the value from the database for a specified condition.How will i compare it with the value assign by me.

I fire a query "select var1,var2,var3 from <sometable> where expirydate="<somedate >

this query give me a 20 rows.After getting that 20 rows i want to compare each rows value with my varibles a1,a2,a3.

i.e a1 should be matched with var1 values of all the row .

so similarly for the other two.

if atleast one value from a1 is contain in var1 then i should get all the values of the column of that particular row returned. so how to solve this problem.

please help me if u can.

java@mania at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

hi Balus C,

You have use a new style of for loop.what is this kind of assignment called and just tell my site where i could read about such type of assignment.

thank u for ur reply.

java@mania at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

> hi Balus C,

>

> You have use a new style of for loop.what is this

> kind of assignment called and just tell my site where

> i could read about such type of assignment.

>

> thank u for ur reply.

That's the For-Each loop. This was available per Java 1.5, together with Generics. Java 1.5 was introduced in the fall of 2004. Not really new though.

Just follow at least a Java 1.5 book/tutorial/course. Java 1.6 don't differ that much from 1.5.

BalusCa at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Thanks Balus C,

for the reply for the for- each.

but how should i mange to work with the resultSet values in form of many rows?

how should i store and compare the value in it.

java@mania at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I don't see a specific question/problem.

I already have given an example code snippet how to compare values. Just apply it on each row.

BalusCa at 2007-7-29 12:05:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...