val resultAsString = for { // open the connection asynchronously connection <- dbSupport.connect() // Execute a query quest dataAsString <- connection.executeQuery( "SELECT first_name,last_name,hire_date FROM employees " + "ORDER BY hire_date DESC " + "LIMIT 0,5", "") { // Instead of creating a result set, we also can directly react // as the data streams in case StartRow(jsonToBuild) => jsonToBuild + "-" case AValue(value, jsonToBuild) => jsonToBuild + "," + value.getString case EndRow(jsonToBuild) => jsonToBuild + "\n" } // When the results arrived, close the connection _ <- connection.close() } yield dataAsString // Process the results resultAsString.onSuccess { case stringData => print(stringData) }.onFailure { case e: Exception => { e.printStackTrace() } }