java - Set SQLite connection properties in c3p0 connection pool -
to specify sqlite connection properties there org.sqlite.sqliteconfig , goes this:
org.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); sqliteconnectionpooldatasource datasource = new sqliteconnectionpooldatasource();
creating connection pool c3p0 goes this:
combopooleddatasource cpds = new combopooleddatasource(); cpds.setdriverclass("org.sqlite.jdbc"); cpds.setjdbcurl("jdbc:sqlite:/foo/bar"); cpds.setmaxpoolsize(10);
question: how create datasource combines two, letting me set things connection pool's max-pool-size , sqlite's synchronous mode?
try
//put imports 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); // unpooled sqlite datasource desired configuration sqlitedatasource unpooled = new sqlitedatasource( config ); // pooled c3p0 datasource wraps unpooled sqlite datasource datasource pooled = datasources.pooleddatasource( unpooled );
the datasource pooled
c3p0 pooleddatasource wraps sqlite unpooled datasource has been configured wish.
please see c3p0's docs, "using datasources factory class", , api docs datasources factory class.
see javadocs sqlite jdbc, downloaded here answer question.
Comments
Post a Comment