Accessing a Firebird Database
We gave detailed instructions in the Database tutorial for getting started with Firebird and for creating and populating the CONTRIBUTIONS.MDB Firebird database. In order to access it from an Oxygene program, you need a reference to the unzipped jaybird-full-2.2.5.jar from the JDBC driver download. (The Java 7 version worked for us).
To add the reference:
- right click on References in the Solution Explorer then select the menu option Add Reference;
- click on the Browse button at the bottom of the new window;
- navigate to the required jar file jaybird-full-2.2.5.jar;
- double click on the filename;
- click the OK button.
This is an snippet from the .oxygene project file after adding the reference to the jaybird jar file:
<ItemGroup> <Reference Include="rt.jar" /> </ItemGroup> <ItemGroup> <Reference Include="C:\Users\PPS\Documents\Jaybird\jaybird-full-2.2.5.jar"> <Private>True</Private> </Reference> </ItemGroup>The Java code on this JavaWorkspace page was most helpful.
namespace TinyFirebirdTest; interface uses java.util, java.sql; implementation var conn : Connection := nil; rs : ResultSet := nil; st : Statement := nil; begin try &Class.forName('org.firebirdsql.jdbc.FBDriver'); //Registers the driver conn:= DriverManager.getConnection( 'jdbc:firebirdsql://localhost:3050/F:/Firebird2/CONTRIBUTIONS.FDB', 'student', 'pp4s'); st:= conn.createStatement; rs := st.executeQuery('SELECT Forename FROM Programmer ORDER BY Forename'); writeLn('Forenames of contributors in alphabetical order:' ); while (rs.next()) do writeLn(rs.getString('Forename')); except on e: Exception do e.printStackTrace; finally try rs.close; st.close; conn.close; except on e: Exception do e.printStackTrace; end; end; System.in.read; end.
Equivalent Code in RemObjects C#
Add the same reference (jaybird-full-2.2.5.jar) as described above for Oxygene.
using java.util; using java.sql; namespace fb_test_cs_java { static class Program { public static void Main(string[] args) { Connection conn = null; ResultSet rs = null; Statement st = null; try { @Class.forName("org.firebirdsql.jdbc.FBDriver"); conn = DriverManager.getConnection( "jdbc:firebirdsql://localhost:3050/F:/CONTRIBUTIONS.FDB", "student", "pp4s"); st = conn.createStatement(); rs = st.executeQuery("SELECT Forename FROM Programmer" + " ORDER BY Forename"); System.@out.println("Forenames of contributors" + " in alphabetical order:" ); while (rs.next()) { System.@out.println(rs.getString("Forename")); } } catch(Exception e) { e.printStackTrace(); } finally { try { rs.close(); st.close(); conn.close(); } catch(Exception e) { e.printStackTrace(); } } System.@in.read(); } } }