A ScalikeJdbc SQL SELECT example with JDBC-style parameters

Here’s another ScalikeJdbc SQL SELECT example. If I remember right, this one doesn’t rely on a configuration file, it just uses the JDBC parameters shown:

import scalikejdbc._

object ScalikeJdbc1Query extends App {

    // initialize JDBC driver & connection pool
    Class.forName("org.h2.Driver")
    ConnectionPool.singleton("jdbc:h2:./test", "sa", "sa")

    // ad-hoc session provider on the REPL
    implicit val session = AutoSession

    // for now, retrieves all data as Map value
    val entities: List[Map[String, Any]] = sql"select * from users"
        .map(_.toMap)
        .list
        .apply()
    entities.foreach(println)

}

FWIW, if you need to connect to MySQL using MAMP (or WAMP), here’s that driver and URL information, circa June, 2020:

Class.forName("com.mysql.cj.jdbc.Driver")
ConnectionPool.singleton(
    "jdbc:mysql://localhost:8889/DB_NAME?useLegacyDatetimeCode=false&serverTimezone=America/Denver",
    "DB_USERNAME",
    "DB_PASSWORD"
)

Just change the database name, username, and password to match your system. Also, your MySQL URL might not require those extra parameters on the end.