在postgresql中使用clojure时,每当我发出的语句以某种方式格式错误或被db本身拒绝时,我都会遇到类似以下错误:
java.sql.BatchUpdateException:
Batch entry 0 drop schema public cascade was aborted.
Call getNextException to see the cause.
如何调用getNextException以便能看到我做错了什么?我从哪里打电话给它?
答案 0 :(得分:7)
请参阅此link on clojure/jdbc,了解如何使用Clojure / JDBC删除表。
它还向您展示了如何使用try catch块处理错误。
从try try块中,您可以编写类似于:
的内容(.printStackTrace (.getCause e))
答案 1 :(得分:2)
我使用以下命令成功删除/创建表,并在postgresql被扰乱时获取准确的错误信息:
(defn drop-table [name]
(sql/with-connection db
(with-open [s (.createStatement (sql/connection))]
(try
(.addBatch s (str "drop table " name ))
(seq (.executeBatch s))
(catch Exception _)))))
(defn setup []
(comment "TODO: create tables here"))
(defn -main []
(try
(print "Dropping table...") (flush)
(drop-table "table_name")
(print "Creating database structure...") (flush)
(setup)
(println " done")
(catch Exception e (.getNextException e))))