Created
March 17, 2015 06:53
-
-
Save maji-KY/646f202cacac855cd8da to your computer and use it in GitHub Desktop.
sample JDBI with hikariCP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.neco_labo.db | |
import com.zaxxer.hikari.{HikariDataSource, HikariConfig} | |
import org.skife.jdbi.v2.{DefaultMapper, DBI} | |
import scala.collection.JavaConverters._ | |
object JDBI extends App { | |
val config = new HikariConfig() | |
config.setJdbcUrl("jdbc:mysql://localhost:3306/db?zeroDateTimeBehavior=round") | |
config.setUsername("user") | |
config.setPassword("pass") | |
config.addDataSourceProperty("dataSourceClassName", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource") | |
config.addDataSourceProperty("autoCommit", "false") | |
config.addDataSourceProperty("useServerPrepStmts", "true") | |
config.addDataSourceProperty("cachePrepStmts", "true") | |
val ds = new HikariDataSource(config) | |
val dbi = new DBI(ds) | |
val h = dbi.open() | |
val result = h.createQuery("select * from table") | |
.map(new DefaultMapper) | |
.iterator().asScala | |
result.foreach(println) | |
h.close() | |
ds.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment