Skip to content

Instantly share code, notes, and snippets.

@takezoe
Created June 30, 2012 01:00
Show Gist options
  • Save takezoe/3021636 to your computer and use it in GitHub Desktop.
Save takezoe/3021636 to your computer and use it in GitHub Desktop.
Simple wrapper for JDBC API in Scala
import jp.sf.amateras.scala.util.Imports._
using(DriverManager.getConnection("")){ implicit conn =>
withTransaction { conn =>
// update
val rows = conn.execute(
"INSERT INTO USER_INFO (USER_ID, USER_NAME) VALUES (?, ?)",
1, "takezoe")
// select
val userList: List[(Int, String)] = conn.select(
"SELECT * FROM USER_INFO WHERE USER_ID = ? ", 1){ rs =>
(rs.getInt("USER_ID"), rs.getString("USER_NAME"))
}
}
}
@takezoe
Copy link
Author

takezoe commented Jun 30, 2012

This is an example of scala-utils's JDBC wrapper. It simplifies JDBC programming in Scala!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment