[SOLVED] ArrayList in Java access Array of value in MySQL


I have a Java bean that has a field like below,

List<String> address = new ArrayList<>();

I also have a table in MySQL database name building and a column name street of its own. when I use JDBC to connect to MySQL database, how can I use this ArrayList to query in MySQL database like SELECT * FROM building WHERE street IN ("Pearl", "Granby"). Or have any better query to execute this connect. Forgive me for my poor language.

I tried to connect directly and get error like:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'building.address IN [Pearl, Grandby]'


String result = address.stream().collect(Collectors.joining("','", "'", "'"));

Answered By – aymcg31

Answer Checked By – Dawn Plyler (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *