1

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.

Fabian N.
  • 3,807
  • 2
  • 23
  • 46
user2752159
  • 1,182
  • 3
  • 13
  • 29
  • The [JayDeBeApi documentation](https://pypi.python.org/pypi/JayDeBeApi/) says: "If you are using cPython ensure that you have installed [JPype](https://pypi.python.org/pypi/JPype1/) properly." Have you done that? – Gord Thompson Jun 21 '16 at 12:05
  • Hi, any chance if you have any steps or the lambda layers that could be shared if you are able to connect to Informix DB from AWS Lambda Python Environment? – ShengHow95 Nov 19 '21 at 09:50

1 Answers1

0

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)
Sven R.
  • 1,049
  • 17
  • 24
stellar
  • 61
  • 1
  • 6
  • This works, but only for one iteration thought the program. If I try to run the same script again several minutes later, I receive the following error: `Unable to start JVM at native/common/jp_env.cpp:78`. Any ideas why this is? – user2752159 Feb 07 '17 at 22:09