Scala using(Hishidama's Scala loan-pattern Memo)
これと、
val s = scala.io.Source.fromFile("C:/temp/a.txt") try { s.getLines.foreach{ println } } finally { s.close() }
これを、
import java.sql.{Connection, DriverManager, ResultSet}; // Change to Your Database Config val conn_str = "jdbc:mysql://localhost:3306/DBNAME?user=DBUSER&password=DBPWD" // Load the driver classOf[com.mysql.jdbc.Driver] // Setup the connection val conn = DriverManager.getConnection(conn_str) try { // Configure to be Read Only val statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) // Execute Query val rs = statement.executeQuery("SELECT quote FROM quotes LIMIT 5") // Iterate Over ResultSet while (rs.next) { println(rs.getString("quote")) } } finally { conn.close }
組み合わせて、ローンパターンでゴニョゴニョしたい。そのうち書き直す。