0

I have an Elastic Beanstalk application that I'm trying to configure to connect to a FileMaker Pro database, over JDBC. The code I'm using is:

import jaydebeapi as jdp

jdbc_driver_location = '/tmp/fmjdbc.jar'

conn = jdb.connect(jdbc_driver_class,
                   jdbc_connection_type + '://' + db_url + '/' + db_name,
                   [user_name, password], jdbc_driver_location,)

When I attempt this, I get the following error:

java.sql.SQLException: No suitable driver found for jdbc:filemaker://10.120.120.108/carecord-<class 'jpype._jexception.java.sql.SQLExceptionPyRaisable'>

To try and solve to problem, I've added the jdbc.jar to both the /tmp folder of the Ec2 instance, as well as included it in the project directory. When if I SSH into the EC2 instance and issue the command:

JAVA_HOME=/tmp/fmjdbc.jar

The program will run the next time it's prompted, without issue. After a few hours it will give the original error and need to be issued the above command again to work. To fix this I tried adding the following to /.ebextensions, to copy the .jar into the tmp folder from the project directory and issue the above command to the server from the start:

commands:
  command01:
    command: sudo cp /opt/python/current/app/fmjdbc.jar /tmp/fmjdbc.jar
  command02:
    command: JAVA_HOME=/tmp/fmjdbc.jar

But the project still gives the error. Any thoughts on how I can add this driver to the classpath such that the job will run consistently?

user2752159
  • 1,182
  • 3
  • 13
  • 29
  • It would help if you could show us the variable contents (without user and password). Do you really get a `XXXXX- – bastian Feb 04 '17 at 09:15
  • The XXX was there to hide the URL of the database in question. The full error message is now shown in the question as it appears in production. – user2752159 Feb 06 '17 at 16:52
  • @bastian I've updated the question above. This issue seems similar to this thread: https://answers.launchpad.net/jaydebeapi/+question/248738, in the program can connect when I manually enter the JAVA_HOME command, but the the driver isn't "sticking" after a period of inactivity. Unfortunately the ticket linked to above did not appear to be resolved. – user2752159 Feb 07 '17 at 15:01

2 Answers2

1

To help folks who have this issue in the future, the answer to this that I found was at the end of this thread.

I appended the following:

if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
    jpype.attachThreadToJVM()
    jpype.java.lang.Thread.currentThread().setContextClassLoader(jpype.java.lang.ClassLoader.getSystemClassLoader())

Just above the

jdbc_driver_location = '/tmp/fmjdbc.jar'

section of my original code above. This allows the application to loop and successfully find the necessary driver.

user2752159
  • 1,182
  • 3
  • 13
  • 29
0

JAVA_HOME is supposed to point to the location where Java is installed on the server. You don't use JAVA_HOME to add libraries to the classpath. You shouldn't have to set any environment variables for your code to work.

The root of your problem is that you are copying the file to /tmp/fmjdbc.jar but you are setting jdbc_driver_location to be /tmp/jdbc.jar. Notice how those file names are different. To fix your code change it to this:

jdbc_driver_location = '/tmp/fmjdbc.jar'
Mark B
  • 183,023
  • 24
  • 297
  • 295
  • Sorry for the confusion! That was just a typo when I was writing out the problem. The variable `jdbc_driver_location` is properly set to `'/tmp/fmjdbc.jar'`, and the issue persists. – user2752159 Feb 03 '17 at 19:31
  • Any idea what would be causing the issue, given that the variable issue was a typo? Again, the code will run on it's first startup, but the `no suitable driver found` error persists on subsequent attempts. – user2752159 Feb 07 '17 at 18:29