Connecting Interbase To Java Applications: Getting and Installing The Driver
Connecting Interbase To Java Applications: Getting and Installing The Driver
To connect to an InterBase database from a Java program we need a driver that is able to communicate
with the two parts. One standard way is to use the JDBC protocol.
The latest version is JDBC2 which should be installed as part of the SDK (Software Development Kit) if
you're using version 1.4 or later.
Borland followed a different track than other DBMS suppliers. To make it faster to download when using
applets they split the driver into two parts. One part (InterServer) would run as a server on the same
computer holding the InterBase DBMS, the other part (InterClient) would be downloaded on the client
running the Java program (or applet).
The communication goes from the Java program to InterClient which is connected to the InterServer that
finally communicates with the InterBase server. The advantage is that only a small part of the driver
needs to be installed on the client.
But as we're running the open source version of InterBase which is not able to run across networks there
is no obvious advantages on the contrary: we need to install everything on the same computer which
then must run two servers (InterBase and InterServer).
To avoid this overhead we'll instead use another driver supplied by IBPhoenix.
IBPhoenix has developed an open source database named Firebird (based on the open source version of
InterBase).
They also developed a JDBC-driver, named JayBird, that doesn't need the InterServer. JayBird works
together with both Firebird and InterBase.
It is this JayBird driver we'll describe in the following.
For further information about Firebird and JayBird see www.IBPhoenix.com, for further information about
InterServer/InterClient see www.Borland.com.
The folder is (probably) placed either directly in the root or in the default folder for programs (Program
Files for English versions of Windows Programmer for Danish versions).
In the installation folder you'll find the folder jre\lib\ext - copy the jar-file firebirdsql-full.jar
into this folder.
The following table shows possible paths to look for (assuming you're using version 1.4.2.03):
C:\j2sdk1.4.2_03\jre\lib\ext
C:\Program Files\j2sdk1.4.2_03\jre\lib\ext
C:\Programmer\j2sdk1.4.2_03\jre\lib\ext
The following Java-program loads the driver, creates a connection and perform some basic SQL on the
database the comments should be self-explaining:
import java.sql.*;
public class JDBCTest {
//Connection to database
private static Connection connection;
//ResultSet used to store results in various methods
private static ResultSet rs;
//Statement used to store SQL-statement in various methods
private static Statement statement;
//close connection
try {
connection.close();
} catch(SQLException sqle) {
System.out.println(sqle + "\nProgram exits");
System.exit(0);
}//try-catch
}//main
}//class JDBCTest