pstmt = conn.prepareStatement("INSERT INTO tableA (userid, itemid) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?");
pstmt.setString(1, userid);
pstmt.setString(2, itemid);
pstmt.setString(3, value);
pstmt.executeUpdate();
This code works
pstmt = conn.prepareStatement("INSERT INTO tableA (userid, itemid) VALUES ((SELECT userid FROM user WHERE userid = ?), ?) ON DUPLICATE KEY UPDATE value = ?");
pstmt.setString(1, userid);
pstmt.setString(2, itemid);
pstmt.setString(3, value);
pstmt.executeUpdate();
This code does not work. What is wrong here? Is there a way that can make the second query run?