I am stuck trying to connect to an embedded Apache Derby Database through my Play (2.3.9) application. Have the following configurations in application.conf:
DATABASE_URL_DB = "derby:MyDB"
db.default.driver = org.apache.derby.jdbc.EmbeddedDriver
db.default.url="jdbc:"${DATABASE_URL_DB}
(I have the MyDB DB directory inside the Derby installation directory - which is the default).
Following is the controller code (a fragment of the file) i am trying to execute:
package controllers
import play.api.db._
import play.api.mvc._
import play.api.Play.current
object Application extends Controller {
def test = Action {
var outString = "Number is "
val conn = DB.getConnection()
try {
val stmt = conn.createStatement
val rs = stmt.executeQuery("SELECT 9 as testkey ")
while (rs.next()) {
outString += rs.getString("testkey")
}
} finally {
conn.close()
}
Ok(outString)
}
}
The dependencies in place (alongside others):
libraryDependencies ++= Seq( jdbc , cache , ws)
libraryDependencies += "org.apache.derby" % "derby" % "10.12.1.1"
In Routes (alongside others):
GET /globalTest controllers.Application.test
I get the error: NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.EmbeddedDriver
Could someone point out the problem? Thanks in advance.
The issue was resolved by minimizing the number of dependencies in build.sbt. Certainly seems like one of the dependencies in my project was interfering with the Derby drivers.