Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slick exception when trying to connect to MySql

Tags:

scala

slick

I am trying to follow the slick2 examples using MySql. however when trying to connect to the database I am getting end exception

import scala.slick.driver.MySQLDriver.simple._
import slickTest.DB.SuppliersEntity

object slickTestDB {

  def main(args: Array[String]) {
    println("CreateDb!")
    val schemaName = "slickTest"
    val conn_str = "jdbc:mysql://localhost:3306/" + schemaName
    val database = Database.forURL(conn_str,user="",password="",driver="com.mysql.jdbc.Driver")
  }
}

getting this exception

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$$anon$4.<init>(JdbcBackend.scala:62)
    at scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forURL(JdbcBackend.scala:61)
    at scala.slick.jdbc.JdbcBackend$$anon$2.forURL(JdbcBackend.scala:23)
    at slickTest.slickTestDB$.main(slickTestDB.scala:18)
    at slickTest.slickTestDB.main(slickTestDB.scala)
like image 614
igx Avatar asked Mar 06 '14 15:03

igx


1 Answers

You probably need to add the MySQL Connector library as a dependency in your project.

libraryDependencies += "mysql" % "mysql-connector-java" % "latest.release"
like image 116
Randall Schulz Avatar answered Nov 04 '22 16:11

Randall Schulz