Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Jython: use Jackcess all the tables from a password-protected MS Access database to CSV
#! /usr/bin/env jython
# Based on
# Install prereqs:
# sudo apt-get install jython libcommons-logging-java libcommons-lang-java
# Put the following jars into the same directory as this file:
# jackcess:
# jackcess-encrypt:
# Bouncy Castle: "Provider" from
import sys
sys.path.append('jackcess-2.1.12.jar') # assume the jackcess is in the same directory
sys.path.append('bcprov-ext-jdk15on-160.jar') # Bouncy Castle encryption library
sys.path.append('/usr/share/java/commons-lang-2.6.jar') # in case lang didn't get picked up
sys.path.append('/usr/share/java/commons-logging-1.2.jar') # in case logging didn't get picked up
from com.healthmarketscience.jackcess import *
from com.healthmarketscience.jackcess.util import ExportFilter
from com.healthmarketscience.jackcess.util import ExportUtil
from com.healthmarketscience.jackcess.util import SimpleExportFilter
from com.healthmarketscience.jackcess import CryptCodecProvider
from import File
import argparse
import os
from getpass import getpass
parser = argparse.ArgumentParser(description='Export all tables from database to CSVs')
parser.add_argument('dbfilename', help='Path of the access file to be exported')
parser.add_argument('exportdirname', help='Path or name of directory to export files to')
args = parser.parse_args()
dbfilename = args.dbfilename
exportdirname = args.exportdirname
print "input filename is",dbfilename
print "tables will be saved into directory",exportdirname
dbfile = File(dbfilename)
exportdir = File(exportdirname)
passwd = getpass("Database password: ")
# make a database object
db = DatabaseBuilder(dbfile).setCodecProvider(CryptCodecProvider(passwd)).open()
# make an export filter object
export_filter = SimpleExportFilter()
# make the output directory
# use 'em to throw down all the data!
print "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment