Set SQLite connection properties in c3p0 connection pool

后端 未结 1 1796
广开言路
广开言路 2021-01-21 01:05

To specify SQLite connection properties there is org.sqlite.SQLiteConfig and it goes something like this:

    org.sqlite.SQLiteConfig config = new org.sqlite.SQL         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 01:46

    Try

    //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 );
    

    The DataSource pooled will now be a c3p0 PooledDataSource that wraps an SQLite unpooled DataSource which has been configured as you wish.

    Please see c3p0's docs, "Using the DataSources factory class", and the API docs for the DataSources factory class.

    See also the javadocs for SQLite JDBC, which I downloaded from here to answer this question.

    0 讨论(0)
提交回复
热议问题