Which Should I use JDBC or Slick?

I am new to Scala and its been progressing pretty good with the help of this community. I am doing a project for myself and It’s basically reading an xml file and inserting the records into Sql Server and that part is done. It’s probably not the best code, but I know it works. 2nd part of the mission is to build a webservice/rest/microservice or something in that area. This will except parameters and return the result set in json. So far I have decided on http4s and its been challenging, but I am starting to understand it. Now the bigger question is which should I use just straight JDBC or Slick to retrieve the data and output to JSON? Thanks in advance.

If you are using http4s then I would guess either doobie or skunk (only if your db is postgres)

Also, I would encourage you to join the typelevel discord server.

By and large, it’s unusual to use raw JDBC nowadays. Slick is a valid and common option, but that project is looking a bit moribund – there haven’t been any releases in a fair while, so it may be stalled out. I currently wouldn’t recommend it for a greenfield project.

I agree with @BalmungSan – at this point, Doobie seems to be the most popular option, and it integrates better with http4s than Slick does. (That is, Doobie is FP-oriented like http4s, which Slick isn’t quite.)

Skunk is one of the most intriguing approaches for Postgres, but I don’t think it’s quite as mature a project yet. But it is by the same lead author as Doobie, and they are somewhat similar, so it shouldn’t be dreadfully hard to start with one of them and switch to the other later if desired. The difference is mainly that Doobie is built on top of JDBC, whereas Skunk talks directly to Postgres, so it is conceptually more powerful.


We’ve had a lot of success with http4s with slick at work, but we have a special case. We support Oracle, MariaDB, and MS SQL Server. We don’t want to write three different dialects of SQL code. Slick writes the SQL for us. That problem used to be very common, but I think is far less so now.

There’s a mild impedance mismatch between http4s’ cats effects and slick’s internal version. I had to stare into the void for an hour to resolve it, but my glue code has not changed since that first fix.

At a previous job - I have coded straight to JDBC in Scala. It works as well as I expected; the code feels very Java-compromising-with-SQL, but Scala helps factor away much of the boilerplate code.

Also, I’ll second BalmungSan’s recommendation to join the typelevel community.

1 Like