首页 > 解决方案 > jdbc PSQLException:错误:“CONFLICT”处或附近的语法错误

问题描述

我正在尝试使用 JDBC 更新我的 postgres DB 中的表,并且对于我的大多数查询来说它工作得很好。但有时我会收到此错误:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "CONFLICT"

当我在 postgres 中手动执行请求时,它工作得很好:

INSERT INTO user_jira (key_user,account_id,name_user,email_adress,display_name,active)
VALUES ('admin','5a283eThisIsJustAnExample','admin','john.john@proceedit.com','john john',true)
ON CONFLICT (key_user) 
DO UPDATE 
  SET account_id=excluded.account_id,
      name_user=excluded.name_user,
      email_adress=excluded.email_adress,
      display_name=excluded.display_name,
      active=excluded.active;

有谁知道发生了什么?编辑:这是我连接到数据库并发送查询的方式:

    String url = "jdbc:postgresql://host:port/db";//connect(url);
    Properties props = new Properties();
    props.setProperty("user","user");
    props.setProperty("password","*********");
    try {
        dyDATAconn = DriverManager.getConnection(url, props);
        System.out.println("connected to "+url);
        Statement st;
         //sql statement
        st = dyDATAconn.createStatement();
        int userRowInserted = st.executeUpdate(User.sqlUpdate(newUser));
        int taskRowInserted = st.executeUpdate(Task.sqlUpdate(allTask));
        int timeSpentRowInserted = st.executeUpdate(TimeSpent.sqlUpdate(allTimeSpent));
        System.out.println("tsk: "+taskRowInserted+"\nTS:"+timeSpentRowInserted);
    } catch (SQLException e) {
        System.out.println("connection to dyJIRA@dyDATA failed");
        System.out.println(User.sqlUpdate(newUser));
        e.printStackTrace();
        return -1;
    }

我无法显示我是如何创建查询的,但我只得到了用户的 pb 并且请求的格式都与上述格式相同

标签: javasqlpostgresqljdbc

解决方案


推荐阅读