试图让ScalikeJDBC和SQLite工作.根据提供的示例提供简单的代码:
import scalikejdbc._, SQLInterpolation._
object Test extends App {
Class.forName("org.sqlite.JDBC")
ConnectionPool.singleton("jdbc:sqlite:test.db", null, null)
implicit val session = AutoSession
println(sql"""SELECT * FROM kv WHERE key == 'seq' LIMIT 1""".map(identity).single().apply()))
}
它失败,例外:
Exception in thread "main" java.sql.SQLException: Cannot change read-only flag after establishing a connection. Use SQLiteConfig#setReadOnly and QLiteConfig.createConnection().
at org.sqlite.SQLiteConnection.setReadOnly(SQLiteConnection.java:447)
at org.apache.commons.dbcp.DelegatingConnection.setReadOnly(DelegatingConnection.java:377)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setReadOnly(PoolingDataSource.java:338)
at scalikejdbc.DBConnection$class.readOnlySession(DB.scala:138)
at scalikejdbc.DB.readOnlySession(DB.scala:498)
...
我已经尝试了scalikejdbc 1.7和2.0,错误仍然存在.作为sqlite驱动程序,我使用“org.xerial”%“sqlite-jdbc”%“3.7.”.
我该怎么做才能解决错误?
最佳答案 我发现原因是你正在使用“org.xerial”%“sqlite-jdbc”%“3.7.15-M1”.此版本看起来仍然不稳定.
使用“3.7.2”和@kawty一样.