使用Clojure和PostgreSQL时,每当我发出的语句存在错误或被数据库本身拒绝时,我会收到类似以下错误:
java.sql.BatchUpdateException:
Batch entry 0 drop schema public cascade was aborted.
Call getNextException to see the cause.
我该如何调用getNextException以查看我的错误信息?在哪里调用它?
使用Clojure和PostgreSQL时,每当我发出的语句存在错误或被数据库本身拒绝时,我会收到类似以下错误:
java.sql.BatchUpdateException:
Batch entry 0 drop schema public cascade was aborted.
Call getNextException to see the cause.
我该如何调用getNextException以查看我的错误信息?在哪里调用它?
(.printStackTrace (.getCause e))
(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))))
(.getCause e)
会抛出NullPointerException
,但是(.getNextException e)
可以正常工作。 - siphiuel