Fork me on GitHub
#sql
<
2023-01-19
>
Asher Serling13:01:23

Hi trying to use Migratus with mysql and getting the following error

; Execution error (ClassCastException) at next.jdbc.prepare$eval3909$fn__3910/invokePrim (prepare.clj:40).
; class com.mysql.cj.jdbc.ConnectionImpl cannot be cast to class java.sql.PreparedStatement (com.mysql.cj.jdbc.ConnectionImpl is in unnamed module of loader 'app'; java.sql.PreparedStatement is in module java.sql of loader 'platform')
this happened on one machine but not another. does anyone have an idea what to do?

adamfrey18:01:47

When I use next.jdbc/execute I can pass {:builder-fn my-custom-builder-fn} opts where my-custom-builder-fn receives a java.sql.ResultSet. Is there any way to somehow pass in a :builder-fn opts when I use create a preparedstatement and pass that to jdbc/plan?

(with-open [stmt (jdbc/prepare conn pg-query {:fetch-size  750
                                              :result-type :forward-only
                                              :concurrency :read-only})]
      (->> (jdbc/plan stmt)
           ...) 

adamfrey18:01:20

perhaps I need to skip calling jdbc/plan and instead call (p/-execute stmt ... {:builder-fn ...}) directly?

adamfrey18:01:32

it does look like that does what I want. writing out the question helped me answer it myself, I guess

seancorfield21:01:08

Why are you creating the PeparedStatement? Why not just call plan with the conn and those options + plus :builder-fn?