ResultSet values to store in arraylist

hello all,

Need help.Please help me in adding all the values from result set to the arraylist.

And also tell me as to how we comparing two string values with delimiter in it.For example :string1 = "Ejb,Jsp,Weblogic9.0,hibernate,jsf"

and string2 = "Weblogic9.0,struts"

in this two string at least one word of two string are matching so i will get the database values.

help me how to do this

[426 byte] By [java@mania] at [2007-11-27 10:46:41]
# 1

> Need help.Please help me in adding all the values

> from result set to the arraylist.

What's the exact question? Tell us where you stucks while writing code. This is really straightforward.

> And also tell me as to how we comparing two string

> values with delimiter in it.For example :string1 =

> "Ejb,Jsp,Weblogic9.0,hibernate,jsf"

> and string2 = "Weblogic9.0,struts"

Read the String API [1]. It provides several useful methods, like indexOf(), contains(), matches(), split(), etcetera.

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

BalusCa at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

this i smy code for the arraylist

stmt=con.createStatement();

String query = "select a1,a2,a3 from usernametable";

rset = stmt.executeQuery(querya);

while(rset.next())

{

record = new ArrayList();

Object value = rset.getString("a1");

record.add(value);

Object value = rset.getString("a2");

record.add(value);

}

return record;

}

but this is not taking the value.

where am i going wrong.

java@mania at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

You are initializing the list object "record" inside the loop.

move the initialization outside the while loop.

R@njita at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

The "querya" is not definied and you're overwriting the record with a new arraylist on every loop.

You should map ResultSet to List<RowObject>, where the RowObject is just a DTO (a simple class with private fields and public accessors, which can be used to transfer the data from layer to layer), which represents one database row.

BalusCa at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hi R@njit and Baclus,

thanks for the reply.

java@mania at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

hi BalusC ,

Sorry for writing ur wrong name in my previous reply.

Can u send simple example or a tutorial site for using the string methods. For using the split(), matches(), contains(). That i would help me for my work .

Mani

java@mania at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Just read the String API how to use them. I have given a link to the String API. Just play with it in a small java application.

BalusCa at 2007-7-28 20:20:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...