score:31
In the SBT project class there should be a line:
// Declare MySQL connector Dependency
val mysql = "mysql" % "mysql-connector-java" % "5.1.12"
This will import the JDBC driver JAR file for MySQL.
Did you load the driver? If you use this Util class to fetch the connections, the driver will be loaded exactly one time:
// Util Class
object DaoUtil {
import java.sql.{DriverManager, Connection}
private var driverLoaded = false
private def loadDriver() {
try{
Class.forName("com.mysql.jdbc.Driver").newInstance
driverLoaded = true
}catch{
case e: Exception => {
println("ERROR: Driver not available: " + e.getMessage)
throw e
}
}
}
def getConnection(dbc: DbConnection): Connection = {
// Only load driver first time
this.synchronized {
if(! driverLoaded) loadDriver()
}
// Get the connection
try{
DriverManager.getConnection(dbc.getConnectionString)
}catch{
case e: Exception => {
println("ERROR: No connection: " + e.getMessage)
throw e
}
}
}
}
The code is taken from a simple SBT - MySQL tutorial I wrote some time ago. If you want to download the complete tutorial, see http://github.com/ollekullberg/SimpleOrder
score:2
The MySQL dependency must be configured in your build.sbt
. Currently the style is to declare library dependencies like so:
libraryDependencies ++= {
val liftVersion = "2.5.1"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile",
//etc
)
}
Add the following inside the Seq
to add mysql:
"mysql" % "mysql-connector-java" % "5.1.+"
Note that the +
means that it will get the latest minor version; anything above 5.1
, such as 5.1.27
(the current version at time of writing).
score:16
In the project/plugins.sbt file add a line
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.12"
Then if your in the sbt shell, restart it.
Source: stackoverflow.com
Related Query
- How to use MySQL JDBC driver in an SBT Scala project?
- How can I use scala sources from a different location in a sbt project and also make it work with IntelliJ IDEA?
- how use import a scala project created with sbt in eclipse?
- How can we read invalid date column in spark scala from mysql server using jdbc driver url (connection)
- How do I tell sbt or scala-cli to use a nightly build of Scala 2.12 or 2.13?
- How do i use play ws library in normal sbt project instead of play?
- How to use plugin in sbt project when only the plugin's sources available?
- How to synchronize Intellij and sbt builds for a scala project
- How do you use play framework as a library, in a scala project
- How to debug a Scala SBT project in IntelliJ 13?
- how can I interop kotlin code in an existing SBT scala project
- How to use scala 2.10 trunk with sbt 0.11.0? (Unresolved dependencies)
- How do I make sbt use the scala binaries from $SCALA_HOME directory?
- how to debug scala sbt project in vs code
- SBT: how to use scala 2.11 libraries in scala 2.12 project
- How to use JSR-223 to get Scala interpreter in sbt console?
- How to use SBT IntegrationTest configuration from Scala objects
- How to avoid adding a 'root' scala sbt project in IntelliJ when defining github dependencies?
- How to setup scala sbt project for nd4j and deeplearning4j
- How to get Intellij to use dependencies from SBT scala
- How to Point Intellij at SBT Libraries for Scala Project
- How to auto re-run sbt project in scala
- How to build an scala sbt project as Android library?
- how to create a connection between scala and mysql using jdbc
- How to configure SBT to use Scala 2.8?
- How do you use `ProjectRef` to reference a local project in sbt 1.x?
- How to use docker task with a sbt multi project
- How to make IntelliJ scala project use Scala 2.9.2 version?
- Connecting mySQL from Scala using JDBC driver
- How to use sbt to specify dependsOn other module with different scala version?
More Query from same tag
- Initializing the factory at compile time
- Intellij CE 2018.2 + SBT in docker container: Remote debug breakpoints not working
- How to create an immutable map/set from a seq?
- Spark flattening out dataframes
- How to parse a Map[String,String] with Argonaut
- environmental variable substitution when including another configuration file in Play 2.2
- How to use ScalaTest Matcher to Test Failure Exception Type?
- Wait in tail recursion for future to complete
- Scala implicit conversion misleading
- How to determine if an array has consecutive integers and if so, how many?
- Multiply elements of list of lists with each other
- Explain some scala code - beginner
- How to add a number on List in Scala(Beginner)
- Scala pattern matching if can be converted to some type
- -bash: scala: command not found
- Understanding Message to Self in Akka
- Scala adding item to seq results in type Equals
- Simple Microservice framework
- How to call a function which returns an int in Scala data frame and append it
- What is a simple way to define a string constant to be the contents of a file at compile-time (in Scala)?
- Scala replace " by \"
- In Scala what is difference Await, Thread.sleep and for comprehensions?
- Boolean logic in lambda calculus in Scala
- Lagom - Could not find Cassandra contact points, due to: access denied
- Best Practice to Load Class in Scala
- SBT Plugin: How to add compiler plugin as a dependency that is not propagated downstream?
- Extract numbers from String Array in Scala
- Inherit from a trait when I instantiate a class
- Convert expression to polish notation in Scala
- Why a encoder is needed for creating dataset in spark