简体   繁体   中英

Connect to Filemaker Database using JDBC, Python, and JayDeBeApi

I'm trying to write an AWS Lambda Python Package that will connect to a FileMaker database over JDBC. To test, I've launched an EC2 instance with the Lambda Linux AMI, and created a virtualenv (/venv) that I'm testing in. I've uploaded the fmjdbc.jar to the instance using WinSCP to /venv/lib/fmjdbc.jar. The code uses JayDeBeApi, following the usage example here: https://pypi.python.org/pypi/JayDeBeApi/#usage

My code so far is the following:

import jaydebeapi as jdb

driverclass = 'com.filemaker.jdbc.Driver'
jdbcURL = 'jdbc:filemaker://url:port;database'


jar = '/home/ec2-user/lambda-test-project/venv/lib/fmjdbc.jar'
print jar

conn = jdb.connect(driverclass,[jdbcURL,'username','password'],jar)

Which gives me the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ec2-user/lambda-test-project/venv/local/lib/python2.7/site-package                                               s/jaydebeapi/__init__.py", line 359, in connect
    jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
  File "/home/ec2-user/lambda-test-project/venv/local/lib/python2.7/site-package                                               s/jaydebeapi/__init__.py", line 183, in _jdbc_connect_jpype
    return jpype.java.sql.DriverManager.getConnection(*driver_args)
jpype._jexception.SQLExceptionPyRaisable: java.sql.SQLException: No suitable driver found for jdbc:filemaker://<MY URL STUFF IS HERE>

How can I get the jdbc driver to be read by Python's virtual environment? I'd like to have this code work in a Lambda package eventually, so I'm hoping there's a solution that can be integrated to the Python code that will work repeatedly on newly created servers.

You can use jpype package to set driver for python. I used it for connecting Oracle DB before. There is my sample code which may be useful for you.

import jaydebeapi,jpype

classpath = "your jdbc jar driver path" 

jvm_path = "/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.36.x86_64/jre/lib/amd64/server/libjvm.so" #your java vm path

jpype.startJVM(jvm_path, "-Djava.class.path=%s" % classpath) #start jvm based on the driver

conn = jaydebeapi.connect(xxxxxx)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM