0

The error

; Execution error (SunCertPathBuilderException) at sun.security.provider.certpath.SunCertPathBuilder/build (SunCertPathBuilder.java:141). ; unable to find valid certification path to requested target

The code (Clojure)

(ns backend.core
  (:require [next.jdbc :as jdbc]))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

(def db {:dbtype "sqlserver" :dbname "dbname" :user "MY_USER" :password "MY_PASSWORD" :host "MY_HOST" :port 1234})
(def datasource (jdbc/get-datasource db))
(defn create-product
  "Create a product."
  [name ds]
  (jdbc/execute! ds [(str "insert into dbo.product (name) value('" name "')")]))
(comment
  (create-product "my-product" datasource))

I'm playing around with clojure/sql server/next.jdbc and trying to work with my distant SQL Server 2017, but this error appear...

It look like I need some certificate. Is it the case? How can I generate it? How can I install it on my dev PC? Should it be install in a specific place?

Raphael
  • 813
  • 1
  • 8
  • 17
  • I'm not sure if this will help for SQL Server 2017, but I have a demo of **jdbc.next** for both Postgres and H2 here: https://github.com/cloojure/demo-jdbc-next – Alan Thompson Mar 30 '22 at 16:08

1 Answers1

0

I fixed my issue by changing the content of the (def db ...). Here is the updated code working.

(ns backend.core
  (:require [next.jdbc :as jdbc]))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

(def db {:jdbcUrl "jdbc:sqlserver://MY_DISTANT_HOST:12345;databaseName=DB_NAME;user=USERNAME;password=MY_PASSWORD;encrypt=true;trustServerCertificate=true"})
(def datasource (jdbc/get-datasource db))
(defn create-product
  "Create a product."
  [name ds]
  (with-open [connection (jdbc/get-connection ds)]
    (jdbc/execute! connection ["insert into dbo.product (name) values (?)" name] {:return-keys true})))
(comment
  (create-product "my-product" datasource))

You can find more information about jdbc connection string here: https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-ver15

I too ran into a second issue after updating the data-source configuration. The error was:

no mssql-jdbc_auth-8.2.1.x64 in java.library.path

I only needed to download zip file here https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15, unzip it and follow instructions inside install.txt and finally restart my IDE (VS Code).

Raphael
  • 813
  • 1
  • 8
  • 17