0

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]'
pmelo
  • 15
  • 5

1 Answers1

0
String result = address.stream().collect(Collectors.joining("','", "'", "'"));
aymcg31
  • 321
  • 1
  • 7