1

I have a Firebird DB file, test.fdb in some directory, I want to access the DB from java application. What are the required libraries files to access.

I am using Jaybird JDBC Driver to access the embedded Firebird database, but I'm getting the error

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jaybird22_x64 in java.library.path

I tried downloading and adding the jaybird22_x64.so file by System.setProperty("java.library.path", "/home/sk/Desktop/Jaybird/"); and also with System.load() and -Djava.library.path

The jaybird folder contains the file jaybird22_x64.so file.

I am using Ubuntu 17.04, with kernel 4.10.0-42-generic

Here is the exception I get.

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jaybird22_x64 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at org.firebirdsql.gds.impl.jni.JniGDSImpl.initJNIBridge(JniGDSImpl.java:64) at org.firebirdsql.gds.impl.jni.JniGDSImpl.(JniGDSImpl.java:25) at org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin.getGDS(EmbeddedGDSFactoryPlugin.java:40) at org.firebirdsql.gds.impl.GDSFactory.getGDSForType(GDSFactory.java:275) at org.firebirdsql.jca.FBManagedConnectionFactory.getGDS(FBManagedConnectionFactory.java:123) at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:130) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at test.TestJavaFireBird.main(TestJavaFireBird.java:33)

Can anyone help, what libraries are required and how to load them?

koiralo
  • 22,594
  • 6
  • 51
  • 72
  • Please specify the **exact** values you used. The `java.library.path` expects a folder containing the .dll (or .so), not the path of the file itself. – Mark Rotteveel Dec 11 '17 at 09:09
  • In any case, it would be simpler to upgrade to Jaybird 3 and follow https://www.lawinegevaar.nl/firebird/jaybird_embedded_example.html – Mark Rotteveel Dec 11 '17 at 09:11
  • I have added jaybird22_x64.so file with full path in the java.library.path – koiralo Dec 11 '17 at 09:12
  • Edit your question and show the exact value, because I don't know if with 'full path' you mean the full path of the folder containing the .so or the full path of the file. You should use the former, not the latter. – Mark Rotteveel Dec 11 '17 at 09:13
  • Could you specify which OS and if Linux, exact kernel version, you are using? Could you also include the full stacktrace of the exception, and not just the message? – Mark Rotteveel Dec 11 '17 at 09:39
  • @MarkRotteveel I have added error message in the question – koiralo Dec 11 '17 at 09:56
  • I'll see if I can reproduce, in the mean time, I suggest you read the article I posted in my second comment, and switch to Jaybird 3 instead. – Mark Rotteveel Dec 11 '17 at 09:58
  • can it be used for linux, I see it for the windows only – koiralo Dec 11 '17 at 10:02
  • See the top of the article, it says: _"This example is Windows (64 bit) specific, but should easily translate to other platforms (just a matter of including the equivalent libraries in the fb folder)."_ In other words, on Linux, take a Firebird 3 install and use the Linux equivalents of the files listed (which usually means: use a '.so' instead of a '.dll'). Or if you want to use Firebird 2.5 or earlier, the equivalent Firebird 2.x files required for embedded. – Mark Rotteveel Dec 11 '17 at 10:03
  • I still get the error Exception in thread "main" java.lang.RuntimeException: Failed to initialize Jaybird native library. This is most likely due to a failure to load the firebird client library. – koiralo Dec 11 '17 at 10:19
  • That would suggest you don't have Firebird client on the search path. – Mark Rotteveel Dec 11 '17 at 10:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/160926/discussion-between-shankar-koirala-and-mark-rotteveel). – koiralo Dec 11 '17 at 11:25

1 Answers1

1

It looks like the binaries from the Firebird website don't work on Ubuntu. So to use Firebird embedded on Ubuntu 17.04, the simplest is to install Firebird 3.0 server using:

sudo apt-get install firebird3.0-server

In the install, make sure to enter a password for the sysdba account.

This will install and start a full Firebird 3.0 server, but the alternative is to compile Firebird yourself. You can stop and disable the server process using

sudo systemctl stop firebird3.0
sudo systemctl disable firebird3.0

Next, you will need to add yourself to the Firebird group to get access to /tmp/firebird for the shared lock-files:

sudo usermod -a -G firebird <your-username>

Reboot to get access to the group. This shouldn't be necessary, but I couldn't get the group without a reboot on my machine.

After getting this working, you can try to get it working without adding yourself to the firebird group by specifying the lock-path using the FIREBIRD_LOCK environment variable.

Next use Jaybird 3.0 and JNA 4.4.0 to run your Java application. If you want to use Jaybird 2.2, you will need to compile the libjaybird22_x64.so yourself.

If you really need to use Firebird 2.5, then you may want to look at https://askubuntu.com/questions/945327/how-to-installing-firebird-on-ubuntu-16-04 although I'm not sure this will still work on 17.04.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197