I have a JSON column that I want to create a prepared statement for, but I'm not sure how to go about it since the parameters for the statement are inside a literal string.
For example:
PreparedStatement stmt = myConn.prepareStatement("SELECT JSON_SET(new_friends, '$.?', '[?]') from friend_list where id = ?");
for (int i = 0; i < new_friends.size(); i++) {
String friend = new_friends.get(i);
// not sure what to put here
stmt.set....
stmt.set....
stmt.set(3, i);
}
Anyone have any suggestions?
JSON_SET(new_friends, ?, ?). In this case for the first placeholder you will pass the value of'$.whatever'and for the second one -'[1,2,3,4,5]'. Note that those should be strings. At least give it a try.JSON_ARRAY_APPEND. dev.mysql.com/doc/refman/5.7/en/…