Postgres JDBC driver: PSQLException: syntax error at or near RETURNING

前端 未结 3 2033
无人共我
无人共我 2021-02-13 14:56

For some reason the JDBC PostgreSQL driver is adding: RETURNING * to the end of select statements. Why?

Code:

protected         


        
3条回答
  •  猫巷女王i
    2021-02-13 15:39

    The easiest way I've done this was adding ";--" at the end of sql code:

    String sql = "INSERT INTO testTable(var1, var2) values ("1","2"), ("1","2") RETURNING id;--";
    
    PreparedStatement ps = getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    ps.executeUpdate();
    ResultSet rs = ps.getGeneratedKeys();
    

提交回复
热议问题