I'm using Java Scripting API to execute some external Python scripts from my Java application. The python scripts use sqlite3 module. Execution of the application is resulting in error
ImportError: No module named sqlite3
As I look into the Lib
directory(which is in the classpath) of Jython, there's no sqlite3 module. Hence, my search begins and I found one _sqlite3.py
file which is an implementation of javasqlite
(http://bugs.jython.org/issue1682864). It's use produced more similar kind of errors.
Then I searched the original python's sqlite3
package(original directory) from the python's standard library location and placed it in the Jython's Lib
folder. It then could not find imported _sqlite
module which is the _sqlite.so
library (actual C implementation).
So, now I need help.
Connect To Database#!/usr/bin/python import sqlite3 conn = sqlite3. connect('test. db') print "Opened database successfully"; Here, you can also supply database name as the special name :memory: to create a database in RAM.
import sqlite3 gives our Python program access to the sqlite3 module. The sqlite3. connect() function returns a Connection object that we will use to interact with the SQLite database held in the file aquarium. db .
Step 1 − Go to SQLite download page, and download precompiled binaries from Windows section. Step 2 − Download sqlite-shell-win32-*. Step 3 − Create a folder C:\>sqlite and unzip above two zipped files in this folder, which will give you sqlite3.
I don't believe there is any way to use a CPython extension in Jython, so you're out of luck there.
There's a Java wrapper for SQLite here: http://www.zentus.com/sqlitejdbc/ This is not going to work quite like a Python database driver, so using it would require some adaptation.
Not fun, but perhaps you (or someone else) could write some Jython around it to produce a drop-in replacement for the sqlite3
module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With