-
-
Save lildata/0c5862930c5b59446067 to your computer and use it in GitHub Desktop.
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
object x { | |
// stream a sql query | |
def sql( str:String ):Stream[ResultSet] = withStatement { s => | |
val rs = s executeQuery str | |
new Iterator[ResultSet] { def hasNext = rs.next ; def next = rs }.toStream | |
} | |
// loan a sql statement | |
def withStatement[R]( f:(Statement) => R ): R = | |
withConn { c => f( c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) ) } | |
// loan a sql connection | |
def withConn[R]( f:(java.sql.Connection) => R ):R = { | |
val conn = DriverManager getConnection "jdbc://..." | |
try f(conn) finally conn.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment