我试图通过我的Play(2.3.9)应用程序连接到嵌入式Apache Derby数据库。在application.conf中进行以下配置:
DATABASE_URL_DB = "derby:MyDB"
db.default.driver = org.apache.derby.jdbc.EmbeddedDriver
db.default.url="jdbc:"${DATABASE_URL_DB}
(我在Derby安装目录中有MyDB DB目录 - 这是默认设置。)
以下是我试图执行的控制器代码(文件的一个片段):
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)
}
}
依赖关系(与其他人一起):
libraryDependencies ++= Seq( jdbc , cache , ws)
libraryDependencies += "org.apache.derby" % "derby" % "10.12.1.1"
在路线中(与其他人一起):
GET /globalTest controllers.Application.test
我收到错误:NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.EmbeddedDriver
有人可以指出问题吗?提前谢谢。