This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-23
Channels
- # announcements (11)
- # architecture (14)
- # babashka (34)
- # bangalore-clj (8)
- # beginners (108)
- # calva (10)
- # cider (19)
- # circleci (9)
- # clj-kondo (19)
- # clojars (4)
- # clojure (62)
- # clojure-australia (2)
- # clojure-europe (62)
- # clojure-italy (14)
- # clojure-nl (8)
- # clojure-poland (1)
- # clojure-spec (14)
- # clojure-uk (59)
- # clojurescript (14)
- # community-development (5)
- # conjure (2)
- # core-async (10)
- # cryogen (1)
- # cursive (11)
- # data-science (1)
- # datahike (13)
- # datomic (21)
- # deps-new (4)
- # ethereum (1)
- # events (4)
- # fulcro (34)
- # helix (2)
- # jobs (2)
- # juxt (33)
- # kaocha (4)
- # lsp (18)
- # malli (4)
- # membrane (2)
- # off-topic (23)
- # re-frame (3)
- # reitit (4)
- # remote-jobs (1)
- # reveal (6)
- # shadow-cljs (47)
- # slack-help (2)
- # spacemacs (5)
- # sql (45)
- # startup-in-a-month (6)
- # testing (4)
- # tools-deps (21)
- # xtdb (4)
Hi, Been awhile since I've used JDBC. I'm having some difficulty getting a connection to a SingleStore (MemSQL)
(def maria-db
{:classname "org.mariadb.jdbc.Driver"
:dbname "db_name"
:maximum-pool-size 5
:pool-name "db-pool"
:username "xxxxx"
:password "yyyyy"
:connection-uri "jdbc:
(j/query maria-db "SELECT * FROM db_name.some_table_name;")
Getting this error message: `(conn=41911492) Access denied for user 'williamswaney'@'z.z.z.z' (using password: NO)`
So it's not getting the username from the config map, nor the password. I tried them in the URI and this time it seems to accept the user and password, but: `Current charset is UTF-8. If password has been set using other charset, consider using option 'passwordCharacterEncoding'`
@U0QNQ3P3L The intent is that you either provide :connection-uri
or you provide other keys and let the Clojure library build the URI for you. You can't provide both.
Also, it's :user
, not :username
(only HikariCP requires :username
-- no idea why it is the odd one out).
in the connection string, the mysql/maria driver has a bug that they aren't handling things correctly ever since the changes in auth for version 8
I'm a bit puzzled what :maximum-pool-size
and :pool-name
are meant to be -- those aren't meaningful to clojure.java.jdbc
(or next.jdbc
) and they won't be valid JDBC properties either with those names.
@U11BV7MTK His connection string does not have credentials in it.
Remove :connection-uri
and let the library build it for you.
> I tried them in the URI and this time it seems to accept the user and password, but: that's what i was responding to
(def maria-db
{:dbtype "mariadb" :classname "org.mariadb.jdbc.Driver"
:dbname "db_name"
:user "xxxxx"
:password "yyyyy"})
You only need :classname
for clojure.java.jdbc
because next.jdbc
already knows the mariadb
data type.
If you need verifyServerCertificate=false&useSSL=true&disableSslHostnameVerification=true
added to the URI that is constructed, pass those in the hash map as well:
:verifyServerCertificate false
:useSSL true
:disableSslHostnameVerification true
So instead of :connection-uri just use :host, :port, :dbtype (not using next.jdbc yet, but might as well as this is just testing for now)
You only need :host
and :port
if they are non-local/non-standard
(although with c.j.j it may need to be told :port 3306
for mariadb
)
So, yeah: dbtype, classname, dbname, host, port, user, password, other options you need.
Cool, thanks for the help @U04V70XH6 and @U11BV7MTK. Working with :user and I'll play around with next.jdbc and the other suggestions.
Hello, I am trying to use jdbc to do some batch insert using jdbc/db-do-commands and a begin end
block, but it doesn't work, I am not sure what would be the best approach
db-do-commands
is intended for DDL, not SQL.
@archibald.pontier_clo If you're just getting started with JDBC in Clojure, take note of what the clojure.java.jdbc
README says on GitHub: "A low-level Clojure wrapper for JDBC-based access to databases. This project is "Stable" (no longer "Active"). It has effectively been superseded by seancorfield/next.jdbc."
Both c.j.j and next.jdbc
have specific ways to do batch inserts but they are different. next.jdbc
has much better documentation 🙂
If you want to insert multiple rows with c.j.j see http://clojure-doc.org/articles/ecosystem/java_jdbc/using_sql.html#inserting-multiple-rows
If you want to insert multiple rows with next.jdbc
see https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/doc/getting-started/friendly-sql-functions#insert-multi
But there are some caveats about batch insertion -- as noted in that doc, and it links you to execute-batch!
for large batches.
I saw the doc for c.j.j about multiple inserts, but does it update if the row already exists ?
They are inserts so, they just insert.
what I am trying to reproduce is a batch INSERT INTO mytable VALUES (...) ON DUPLICATE KEY UPDATE ...
If you want more control, you need to supply the SQL yourself with execute-batch!
in next.jdbc
.
What DB are you using?
Ah, I figured it was MySQL maybe since ON DUPLICATE KEY
is not standard SQL.
Which reminds me, I need to add support for that in HoneySQL 2.0 under the :mysql
dialect (it already supports all the PostgreSQL upserting stuff).
is the difference between execute-batch!
and execute!
mainly that execute-batch
wraps the query into a begin ... end
?
@archibald.pontier_clo No. Did the documentation not make sense to you?
Did you read https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/doc/getting-started/prepared-statements ?
Unfortunately, there's quite a lot of JDBC machinery that you need to be aware of to work effectively with databases -- and every database has its own strange quirks.