Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@IzumiSy

Heroku上でScalikeJDBCからPostgreSQLを使う際のメモ

More than 1 year has passed since last update.

やること

以下の設定をどこかに記述する

  Try {
    sys.env("DATABASE_URL")
  } match {
    case Success(dbUrl) => {
      val uri = new java.net.URI(dbUrl)
      val userName = uri.getUserInfo().split(":")(0)
      val password = uri.getUserInfo().split(":")(1)
      ConnectionPool.singleton(s"jdbc:postgresql://${uri.getHost}:${uri.getPort}${uri.getPath}", userName, password)
    }
    case _ =>
      ConnectionPool.singleton("jdbc:postgresql://localhost:5432/hoge", "user", "password")
  }

解説

Heroku から渡される DATABASE_URL のフォーマットは以下の様になっているが。これだとScalikeJDBCは受け付けてくれない。

postgres://<username>:<password>@<host>/<dbname>

なので上のコードを使って以下のフォーマットに変換してやる必要がある

jdbc:postgresql://<host>:<port>/<dbname>?sslmode=require&user=<username>&password=<password>

参照: https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-java

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
IzumiSy
Elmエンジニャー / https://dev.to/izumisy
fringe81
Fringeは、最新のテクノロジーとプロフェッショナルによるサービスにより、社会課題に仮説を立てて市場に広げていくことで、数十年という長期的なスパンで価値を生み出し続け、より良い世界を創る集団です。 既存の領域に限らず、時流を読み、仮説を生み出し、テクノロジーの力で優れたサービスを生み出し続けます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?