scalikejdbc 学习笔记
Posted AK47Sonic
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scalikejdbc 学习笔记相关的知识,希望对你有一定的参考价值。
使用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 学习笔记的主要内容,如果未能解决你的问题,请参考以下文章
ScalaScala使用scalikejdbc工具连接MySQL(推荐)
[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段