Firebird embedded with Java?

132 views
Skip to first unread message

Adam McMahon

unread,
Aug 12, 2020, 1:31:49 PM8/12/20
to firebird-java
Hi,

I would like to explore using FB embedded, but I am not quite sure what embedded means for FB:

[1] Does embedded mean that the server is embedded (and then connected to via a wire protocol?) 

[2] Or can we embed the database similar to SQLITE (H2, DERBY, etc), such that there can be no server running and JDBC bypasses a wire protocol altogether.

Mark Rotteveel

unread,
Aug 12, 2020, 1:41:58 PM8/12/20
to firebi...@googlegroups.com
It is option 2. Firebird Embedded is a native library (or rather a
collection of native libraries) that contains the Firebird database
engine, but not its networking components. Jaybird can load this native
library inside your Java process, and talk to it directly using JNA (no
networking is involved). Firebird Embedded offers all features of the
normal Firebird Server engine (except things like network access and
authentication).

In this, it is similar to SQLite, H2 and Derby are slightly different
beasts, as those are pure Java database engines (though in usage there
is no real difference).

A few years ago, I wrote a short article about using Firebird Embedded,
you can find it at
https://www.lawinegevaar.nl/firebird/jaybird_embedded_example.html

Jaybird 5 will introduce a feature that makes it easier to load Firebird
Embedded by loading it from a jar file on the classpath instead of
requiring you to deploy it yourself (it is not entirely finished yet
though).

Mark
--
Mark Rotteveel

Adam McMahon

unread,
Aug 12, 2020, 2:06:02 PM8/12/20
to firebi...@googlegroups.com
>>Jaybird 5 will introduce a feature that makes it easier to load Firebird
Embedded by loading it from a jar file on the classpath instead of
requiring you to deploy it yourself (it is not entirely finished yet
though).

This sounds perfect.  I know SQLITE has this ability. Packing it into a jar would be excellent. 
-Adam

--
You received this message because you are subscribed to the Google Groups "firebird-java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-jav...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-java/7ba393ce-fe6c-d552-12f2-bd5c568aa66b%40lawinegevaar.nl.

Adam McMahon

unread,
Aug 12, 2020, 4:42:17 PM8/12/20
to firebird-java
Mark,

You instructions for Windows embedded worked perfectly.  Thanks!  A few follow up questions:

[1] Your graddle example uses a trimmed down collection of dlls and files, but is there any danger of just pointing the JNA path to a standard FB install folder (as opposed to a trimmed down one)?  In my quick test, it seems to work when pointing to the standard FB install folder.

[2]  what is the String literal name of the embedded driver?  I like to catch problems early by calling, Class.forName(), but I can't find the String literal name of driver.

Mark Rotteveel

unread,
Aug 13, 2020, 2:14:37 AM8/13/20
to firebi...@googlegroups.com
On 12-08-2020 22:42, Adam McMahon wrote:
> You instructions for Windows embedded worked perfectly.  Thanks!  A few
> follow up questions:
>
> [1] Your graddle example uses a trimmed down collection of dlls and
> files, but is there any danger of just pointing the JNA path to a
> standard FB install folder (as opposed to a trimmed down one)?  In my
> quick test, it seems to work when pointing to the standard FB install
> folder.

That works just fine, but trimming down allows you to reduce space and
lock things down more (as in, not giving your users unnecessary
executables).

In fact, usually when I run the Jaybird tests for Embedded, I just point
the jna.library.path to a Firebird installation directory.

You may also want to edit the Providers setting in firebird.conf to only
Engine12 if you need to prevent it from making remote connections.

> [2]  what is the String literal name of the embedded driver?  I like to
> catch problems early by calling, Class.forName(), but I can't find the
> String literal name of driver.

Jaybird has a single driver class, and that is
org.firebirdsql.jdbc.FBDriver, the various types (PURE_JAVA, OOREMOTE,
NATIVE, LOCAL and EMBEDDED) are loaded internally.

See also:
-
https://firebirdsql.github.io/jaybird-manual/jaybird_manual.html#connection-drivermanager
-
https://firebirdsql.github.io/jaybird-manual/jaybird_manual.html#driver-types
-
https://github.com/FirebirdSQL/jaybird/blob/master/src/main/org/firebirdsql/gds/impl/GDSFactory.java

Know that since Java 6 you don't really need to explicitly load a JDBC
driver using Class.forName anymore, unless the driver is not on the
initial classpath (eg if the driver is in WEB-INF/lib of a WAR, but in a
web applications it is usually better to use a configured
javax.sql.DataSource anyway). DriverManager takes care of automatically
loading JDBC drivers on the initial classpath.

Mark
--
Mark Rotteveel
Reply all
Reply to author
Forward
0 new messages