'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<>();
address.add("Pearl");
address.add("Granby");
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]'
Solution 1:[1]
String result = address.stream().collect(Collectors.joining("','", "'", "'"));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | aymcg31 |
