I want to create a list with my database field values.
There are 2 columns, name and surname.
I want to create a list that stores all names in name column in a field and then add to my DTO.
Is this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Steps you can follow: –
First you need to have a
List<String>that will store all your names. Declare it like this: –Now, you have all the records fetched and stored in
ResultSet. So I assume that you can iterate overResultSetand get eachvaluesfrom it. You need to useResultSet#getStringto fetch thename.Now, each time you fetch one record, get the
namefield and add it to your list.Now, since you haven’t given enough information about your
DTO, so that part you need to find out, how to add thisArrayListto yourDTO.The above
listonly containsnameand notsurnameas you wanted onlyname. But if you want both, you need to create a custom DTO(FullName), thatcontains
nameandsurnameas fields. And instantiate it fromevery
ResultSetand add it to theList<FullName>