【发布时间】:2019-12-08 21:11:21
【问题描述】:
我需要获得一个 SQLite 只读 C3P0 ComboPooledDataSource。我在这里找到的这段代码 (Set SQLite connection properties in c3p0 connection pool) 创建了一个 SQLite 只读数据源:
//put the imports where they really go, obviously...
import javax.sql.*;
import org.sqlite.*;
import com.mchange.v2.c3p0.*;
// configure SQLite
SQLiteConfig config = new org.sqlite.SQLiteConfig();
config.setReadOnly(true);
config.setPageSize(4096); //in bytes
config.setCacheSize(2000); //number of pages
config.setSynchronous(SQLiteConfig.SynchronousMode.OFF);
config.setJournalMode(SQLiteConfig.JournalMode.OFF);
// get an unpooled SQLite DataSource with the desired configuration
SQLiteDataSource unpooled = new SQLiteDataSource( config );
// get a pooled c3p0 DataSource that wraps the unpooled SQLite DataSource
DataSource pooled = DataSources.pooledDataSource( unpooled );
它工作正常。但是我试图适应的方法返回一个 ComboPooledDataSource。我怎样才能得到一个?
【问题讨论】:
-
我只需要使用 C3P0 为 SQLite 获取只读连接。我尝试使用推荐的 ConnectionCustomizer,但收到错误消息:建立连接后无法更改只读标志。使用 SQLiteConfig#setReadOnly 和 SQLiteConfig.createConnection()。所以连接必须在创建之前设置为只读。上面的代码有效,只是我需要一个 ComboPooledDataSource 而不是 DataSource
-
你试过我的回答来使用 HikariCP 吗?
标签: java sqlite jdbc datasource c3p0