27.10.2013 Views

Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird

Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird

Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PURE_JAVA <strong>driver</strong> when connecting the server on the same host. This is mostly<br />

due to the fact that TCP/IP stack is not involved in this mode.<br />

In order to instantiate a connection using the NATIVE <strong>JDBC</strong> <strong>driver</strong> to connect to<br />

a remote server you have to use the following <strong>JDBC</strong> URL with new subprotocol:<br />

jdbc:firebirdsql:native:host[/port]:<br />

When connecting to a local database server using the LOCAL <strong>driver</strong>, you should<br />

use following:<br />

jdbc:firebirdsql:local:<br />

Additionally to the <strong>Firebird</strong> client library installation, <strong>driver</strong> requires a JNI proxy<br />

to be available to the JVM. The JNI proxy is a platform-dependent dynamically<br />

linked library that translates GDS calls into <strong>Firebird</strong> API calls.<br />

Windows<br />

On Windows, the JNI proxy is represented by a dynamically linked library (DLL)<br />

jaybird21.dll. You have to make this library available through PATH<br />

environment variable. Alternatively you can specify the directory containing this<br />

DLL in java.library.path system property.<br />

For example, if you put library in the current directory you have to use the<br />

following command to start <strong>Java</strong>:<br />

java -Djava.library.path=. com.mycompany.MyClass<br />

Linux<br />

On Linux JNI proxy is represented by a shared library libjaybird21.so. It must<br />

be available through the LD_PATH environment variable. Usually shared libraries<br />

are stored in the /usr/lib/ directory; however you will need root permissions to<br />

copy libjaybird21.so there. Alternatively you can specify directory containing<br />

the proxy in java.library.path <strong>Java</strong> system property. See Windows example<br />

above for more details.<br />

Limitations<br />

<strong>Firebird</strong> client library is not thread-safe when connecting to a local database<br />

server using IPC. <strong>Jaybird</strong> provides the necessary synchronization in <strong>Java</strong> code<br />

using a static object instance. However, this static object instance is local to the<br />

classloader that has loaded the <strong>Jaybird</strong> classes.<br />

In order to guarantee correct synchronization , the <strong>Jaybird</strong> <strong>driver</strong> must be loaded<br />

by the top-most classloader. For example, when using the Type 2 <strong>JDBC</strong> <strong>driver</strong><br />

with a web or application server, you have to add the <strong>Jaybird</strong> classes to the main<br />

classpath (for example, to the lib/ directory of your web or application server),<br />

but not to the web or J2EE application, e.g. the WEB-INF/lib directory.<br />

EMBEDDED type<br />

The Embedded server <strong>JDBC</strong> <strong>driver</strong> is the Type 2 <strong>JDBC</strong> <strong>driver</strong> that rather than<br />

using the <strong>Firebird</strong> client library, loads <strong>Firebird</strong> embedded server library instead.<br />

This is the highest performance type of <strong>JDBC</strong> <strong>driver</strong> for accessing local databases,<br />

as the <strong>Java</strong> code accesses the database file directly.<br />

In order to obtain a connection via DriverManager you have to use following<br />

URL:<br />

Chapter 2. Obtaining a connection 14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!