2
2

More than 5 years have passed since last update.

Play2.0でMySQLにつなぐ

Posted at

jdbcのドライバがないと言われたので、mysql-connector-j.rbを書いてhomebrewでインストールした。

/usr/local/Library/Formula/mysql-connector-j.rb
#http://goo.gl/4pkdPからコピペ
require 'formula'

class MysqlConnectorJ < Formula
  homepage 'http://dev.mysql.com/downloads/connector/j/5.1.html'
  url 'http://downloads.mysql.com/archives/mysql-connector-java-5.1/mysql-connector-java-5.1.13.zip'
  md5 '2e1bbd848bc99fe1c8ae9ce980adc2c9'
  def install
    prefix.install ['README', 'COPYING', 'mysql-connector-java-5.1.13-bin.jar']
  end

  def caveats
    <<-EOS.undent
      To enable Java to find Connector/J, add the following to the
      front of your CLASSPATH:
        #{prefix}
      If this is an upgrade and you have previously added the symlinks
      to your CLASSPATH, you will need to modify it to the path specified
      above so it points to the new version.
    EOS
  end
end

インストールしたあと下記のようにファイルを設定した(たぶん再コンパイル必要)

testproject/project/Build.scala
import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "testproject"
    val appVersion      = "1.0-SNAPSHOT"

    val appDependencies = Seq(
      // Add your project dependencies here,
      "mysql" % "mysql-connector-java" % "5.1.13"
    )

    val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
      // Add your own project settings here      
    )

}
testproject/conf/application.conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://host/databasename?characterEncoding=UTF8"
db.default.user=user
db.default.password=password
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2