简体   繁体   English

Clojure PostgreSQL JDBC不断出现执行查询错误

[英]Clojure PostgreSQL JDBC keep getting error executing query

i hope someone could help me with this, 我希望有人可以帮助我,

So i'm building database backed website with clojure and postgresql, but i keep getting error. 所以我正在用clojure和postgresql构建数据库支持的网站,但是我一直出错。 Here are the code and error on REPL: 以下是REPL上的代码和错误:

(ns app.config-postgre
  (require [clojure.java.jdbc :as sql]))

(def db1
  {:classname "org.postgresql.Driver"
   :subprotocol "postgresql"
   :subname "//localhost:5432/dbname"
   :username "username"
   :password "password}) 
;;that's not the real username and password, the real one is right

here goes the code that caused error : 这里是导致错误的代码:

(sql/insert! db1 :user123
             {:username "user" :password "pass" :user-id "1"})
;;PSQLException ERROR: syntax error at or near "user"
  Position: 43  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

and

(sql/execute! db1 ["INSERT INTO user123 VALUES ('{\"user\", \"pass\" ,1}')"])
;;PSQLException ERROR: null value in column "password" violates not-null constraint
  Detail: Failing row contains ({user,pass,1}, null, null).  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

and

(sql/execute! db1 ["INSERT INTO user123 VALUES ('{\"user\"},{\"pass\"},{1}')"])
;;PSQLException ERROR: malformed array literal: "{"user"},{"pass"},{1}"
  Detail: Junk after closing right brace.
  Position: 29  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

and

(sql/execute! db1 ["INSERT INTO user123 VALUES ('\"user\",\"pass\",1')"])
;;PSQLException ERROR: malformed array literal: ""user","pass",1"
  Detail: Array value must start with "{" or dimension information.
  Position: 29  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

and

(sql/execute! db1 ["INSERT INTO user123 VALUES ('user','pass',1)"])
;;PSQLException ERROR: malformed array literal: "user"
  Detail: Array value must start with "{" or dimension information.
  Position: 29  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

Any suggestion? 有什么建议吗? Thank you in advance 先感谢您

edit schema for table user123 : 编辑表user123的模式:

CREATE TABLE user123
(
  username character varying(100)[] NOT NULL,
  password character varying(100)[] NOT NULL,
  "user-id" integer NOT NULL,
  CONSTRAINT user_pkey PRIMARY KEY ("user-id")
)

使用(sql/execute! db1 ["INSERT INTO user123 VALUES (?, ?, ?)" "user" "pass" 1])

(sql/execute! db1 ["INSERT INTO user123 VALUES ({'user'}, {'pass'}, 1);"])

我认为您应该在数据库规范中将:username更改为: user

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM