• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL query reading from arraylist ?

 
Santosh Kumar Nayak
Ranch Hand
Posts: 147
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we have a sql query reading values from an ArrayList ?

Some thing like this :--

select a, b,c
from <table_name>
where employee_name IN ( arraylist )


Is there any way out ?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santosh,

Are you creating this query using string concatenation ?

-- Srikkanth
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look here and here.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 147
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the help above I am planning to implement the same as below. It is a piece of pseudo code as of now. Please provide your valuable feedback on the same :-

The query will fetch the results based upon the values present in the ArrayList.




 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh Kumar Nayak wrote:Using the help above I am planning to implement the same as below. It is a piece of pseudo code as of now. Please provide your valuable feedback on the same :-

Do you really want to execute a seperate query for each user id in the ArrayList? Why not using 1 query to return all data using WHERE user_id IN (?, ?, ..., ?)?

You are executing a query to retrieve user_id and username, but you are getting empname and empage
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic