File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes sqlite and spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "sqlite and spring" Watch "sqlite and spring" New topic

sqlite and spring

Gobind Singh
Ranch Hand

Joined: Aug 04, 2006
Posts: 62
Anyone had any success in getting sqlite and spring working with foreign key support enabled? By default foreign key support is disabled in sqlite. The documentation at mentions that you have to enable it for each database connectiion separately. I am sure that the version of sqlite I have got supports foreign keys (downloaded it only last week).

to test: If I key in PRAGMA foreign_keys; I get back 0. Which means foreign keys is switched off but support for it exists.

My datasource is defined in spring as :

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverclass}"/>
<property name="url" value="${jdbc.url}"/>
How do I enable foreign keys through spring configuration?
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

maybe try

[How To Ask Questions][Read before you PM me]
Gobind Singh
Ranch Hand

Joined: Aug 04, 2006
Posts: 62
The following seems to work:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name = "connectionInitSqls">
<list><value>PRAGMA foreign_keys = ON</value></list>
I agree. Here's the link:
subject: sqlite and spring
It's not a secret anymore!