Using Scala with JDBC to connect to MySQL
Jun 26 2010
A quick howto on connecting Scala to a MySQL database using JDBC. There are a number of database libraries for Scala, but I ran into a problem getting most of them to work. I have the highest hopes for Querulous, a library created by Twitter. However, it currently only supports Scala 2.7.7 and I’m running a 2.8 candidate which is the only compatible version with the template engine I’m using. Hopefully things stabilize once 2.8 is final.
I attempted to use scala.dbc, scala.dbc2 and Scala Query but either they aren’t supported, have a very limited featured set or abstracts SQL to a weird pseudo language. So I ended up with basic Java JDBC and it turned out to be the easiest solution.
Here is the code for the a database query example using JDBC. You need to change the connection string parameters and modify the query for your database.
01
import j