首页 > 代码库 > scalikejdbc 学习笔记(2)
scalikejdbc 学习笔记(2)
使用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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。