java - 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 并且请求的格式都与上述格式相同
解决方案
推荐阅读
- windows-services - 无法使用 Process.Start() 启动 bat 文件
- tensorflow - 我已将输入和目标标准化,但网络输出超出范围
- shopify - ✗ 'shopify node serve' 导致 - ngrok 隧道已超时,正在重新启动......
- javascript - 什么是 Fuse JavaScript search() 函数在数组上的 Big-O,由 Order 对象组成。请参阅下面的订单对象
- jquery - 当jquery laravel中有多个同名类时获取特定值
- sql - 我已经为 PLSQL 异常处理程序编写了代码,但它仍然没有通过 HackerRank 中的测试用例
- php - 作曲家安装给出未捕获的类型错误
- python - 我的感知器模型出错
- python - auto_arima 在不同时期给出相同的结果?
- javascript - Axios POST 请求 - 设置标头