我想設置PRAGMA foreign_key = ON;在sqlite數據庫。我使用jdbc driver for sqlite編寫了一些軟件,這是一個:http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC。SQLite JDBC PRAGMA設置
我也在使用連接池來加速對數據庫的查詢。我正在使用這個庫: http://commons.apache.org/dbcp/。
到目前爲止,一切都很好。現在,我需要設置PRAGMA設置,具體是PRAGMA foreign_key = ON;在創建表之前,因爲我需要確定db中某些列之間的一致性。
當我創建DB時,它會自動設置爲OFF。所以我必須打開它才能使用它。
但我不知道該怎麼做,我正在準備可池化的數據源的方式是這樣的:
public static DataSource getDataSource(String connectURI) {
GenericObjectPool connectionPool = new GenericObjectPool(null);
ConnectionFactory connectionFactory =
new DriverManagerConnectionFactory(connectURI, null);
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
DataSource dataSource = new PoolingDataSource(connectionPool);
return dataSource;
}
但我不知道如何正確設置編譯,我發現這一個是可能的:
SQLiteConfig config = new SQLiteConfig();
config.enforceForeignKeys(true);
但我不知道如何與池化棘手的設置連接使用它...
任何想法?
This [link] [1]可能會有所幫助。 [1]:http://code-know-how.blogspot.ru/2011/10/how-to-enable-foreign-keys-in-sqlite3.html – Marco167 2013-11-28 14:39:22