我想设置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