-
-
Notifications
You must be signed in to change notification settings - Fork 23
Connect with DriverManager
java.sql.DriverManager
is the first and most simple way to access a JDBC driver. A type 4 JDBC driver does not require any special configuration. You make it available to your application via the classpath as any regular JDBC driver. Type 2 and Embedded Server JDBC drivers require a JNI link to access client or embedded server libraries. This puts additional requirements on the configuration.
java.sql.DriverManager
is the first and the most simple way to access drivers using JDBC driver. Starting with Java 6 (JDBC 4.0) the DriverManager
will automatically load JDBC drivers that are on the classpath (provided the driver provides an entry in /META-INF/services/java.sql.Driver
), removing the need for specifically loading a driver.
You can connect to the database as follows.
Using default configuration:
import java.sql.*;
...
Connection connection = DriverManager.getConnection(
"jdbc:firebirdsql://localhost:3050/c:/database/employee.fdb",
"SYSDBA",
"masterkey");
Using custom connection parameters:
import java.util.*;
import java.sql.*;
...
Properties props = new Properties();
props.setProperty("user", "SYSDBA");
props.setProperty("password", "masterkey");
props.setProperty("encoding", "UTF8");
Connection connection = DriverManager.getConnection(
"jdbc:firebirdsql://localhost:3050/c:/database/employee.fdb",
props);
You can find more information on JDBC in the JDBC Tutorial
In some cases (and Java 5 or earlier) you may need to explicitly load a driver. JDBC supports the following methods.
You can include a list of JDBC driver classes to load in the jdbc.drivers
startup JVM property, for example the JVM startup may look like below
java -cp jaybird-full-2.2.2.jar;myapplication.jar
-Djdbc.drivers=org.firebirdsql.jdbc.FBDriver org.my.Application
Alternatively you can tell the Driver
to register itself in the java.sql.DriverManager
class. This is done by triggering the static class initializer by explicitly loading the driver class:
Class.forName("org.firebirdsql.jdbc.FBDriver");
TODO: Requires additional info
The Type 2 JDBC driver requires the following components to be installed on the client computer
- Firebird client (
fbclient.dll
and corresponding files and registry entries); - Jaybird JNI library,
jaybird22(_x64).dll
on Windows andlibjaybird22(_x64).so
on Linux.
The Jaybird JNI library should be accessible to JVM. This means that it must be either located in path(%PATH%
on Windows or $PATH
on Linux) or the directory where the library is located must be specified in java.library.path
startup property of the JVM. The Firebird client library should be accessible through PATH environment variable (java.library.path
is not taken into the account).
The same requirements as above, however the library in this case should be fbembed.dll
on Windows or libfbembed.so
on Linux.
You should NOT rename fbembed.dll
into fbclient.dll
, as suggested in README for Firebird Embedded. This step is needed only for drivers and database access components that do not support Firebird Embedded directly. This is not the case with Jaybird.