Fork me on GitHub

hello everyone, im new to clojure and the JVM in general... i have an existing database, which is, unfortunately full of triggers .. i have a field (phone region prefix) which isnt optional ( you have to provide a value ), but there are triggers that calculate those values and input them for me if i try to make a insert statement on the mysql CLI, everything goes fine, but when i try to run it via JDBC I get an java exception java.sql.SQLException: field 'ddd' doesn't have a default value


is there a way to mimic the CLI behaviour?

(defn create-usuer
  [^String email ^String phone ^String username ^String cpf]
  (jdbc/insert! db :tb_usuario {:tipo "p"
                                :logado 0
                                :ativo 1
                                :idPaisTelefone1 1
                                :telefone1 phone
                                :usuario email
                                :email email
                                :senha "hash the cpf"
                                :celular phone
                                :cpf cpf
                                :dataCriacao "NOW()"
                                :dataAtualizacao "NOW()"
                                :nome username}))
this is how im trying to insert it


I’m surprised the insert via CLI allows you to omit ddd given that it’s non-null and has no default value. The exception you get is exactly what I’d expect from JDBC: a non-null field with no default value has to have some value provided in the insert statement.


The triggers only fire “after” the insert so you have to satisfy that basic constraint first.


Ah, I see you also asked this in #clojure and got pointed to a forum posting as to why the CLI behavior differs...


thanks for the fast response 🙂


I see you also posted to the java.jdbc mailing list, so I’ll post that forum link in response so folks have that information in the archives (thanks @hiredman )