码迷,mamicode.com
首页 > 数据库 > 详细

scalikejdbc 学习笔记(2)

时间:2017-06-24 22:40:41      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:src   rod   readonly   initial   logs   setup   class   conf   driver   

使用scalikejdbc config (src\main\resources)

# MySQL(dev)
dev.db.default.driver="com.mysql.jdbc.Driver"
dev.db.default.url="jdbc:mysql://192.168.1.151:3306/scalalearning?useUnicode=true&characterEncoding=UTF8"
dev.db.default.user="root"
dev.db.default.password="12345"

# Connection Pool settings
dev.db.default.poolInitialSize=5
dev.db.default.poolMaxSize=7
dev.db.default.poolConnectionTimeoutMillis=1000
dev.db.default.poolValidationQuery="select 1 as one"

# MySQL(prod)
prod.db.default.driver="com.mysql.jdbc.Driver"
prod.db.default.url="jdbc:mysql://192.168.1.151:3306/scalalearning?useUnicode=true&characterEncoding=UTF8"
prod.db.default.user="root"
prod.db.default.password="12345"

# Connection Pool settings
prod.db.default.poolInitialSize=5
prod.db.default.poolMaxSize=7
prod.db.default.poolConnectionTimeoutMillis=1000
prod.db.default.poolValidationQuery="select 1 as one"
import scalikejdbc._
import scalikejdbc.config._

object ConfigDemo {
  def main(args: Array[String]): Unit = {

    DBsWithEnv("dev").setupAll()

    case class User(id: Int, name: String, age: Int)

    val allColumns = (rs: WrappedResultSet) => User(
      id = rs.int("id"),
      name = rs.string("name"),
      age = rs.int("age"))

    val users: List[User] = DB readOnly { implicit session =>
      SQL("select * from user limit 10").map(allColumns).list.apply()
    }

    for (user <- users) {
      println(user.id + "," + user.name + "," + user.age)
    }

    DBsWithEnv("dev").closeAll()
    
  }
}

  

scalikejdbc 学习笔记(2)

标签:src   rod   readonly   initial   logs   setup   class   conf   driver   

原文地址:http://www.cnblogs.com/AK47Sonic/p/7074523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!