Thursday, June 23, 2011

Using Jaybird Firebird JDBC driver with Ubuntu/Debian - cli way

I have used eclipse to create  simple console projects before and there it's easy to add references to the jaybird-full-*.jar , This time i wanted to compile from the shell.

Download jaybird from firebird jdbc download page
unzip it somewhere in your home
I usually put in a dir named  jdbc_client

cd ~/jdbc_client
compile it
javac -cp jaybird-full-2.1.6.jar examples/DriverExample.java
run it
java -cp jaybird-full-2.1.6.jar:examples DriverExample
It will trow you
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jaybird21 in java.library.path


Simple fix is to use the pure type4 java jdbc driver and this is done by using the magic "localhost/3050:" in the connection string



After that it starts ok
java -cp jaybird-full-2.1.6.jar:examples DriverExample
Firebird JCA-JDBC driver version 2.0 registered with driver manager.
Connection established.
Auto-commit is disabled.
Transactions are supported.
PHONE_LIST is a view.
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544558. Operation violates CHECK constraint INTEG_30 on view or table EMPLOYEE
At trigger 'CHECK_4'
 at org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.java:273)
 at DriverExample.main(DriverExample.java:296)
at org.firebirdsql.gds.GDSException: Operation violates CHECK constraint INTEG_30 on view or table EMPLOYEE
At trigger 'CHECK_4'
 at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2169)
 at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2119)
 at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlExecute2(AbstractJavaGDSImpl.java:1185)
 at org.firebirdsql.gds.impl.GDSHelper.executeStatement(GDSHelper.java:226)
 at org.firebirdsql.jdbc.AbstractStatement.internalExecute(AbstractStatement.java:1102)
 at org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.java:269)
 at DriverExample.main(DriverExample.java:296)
Unable to increase everyone's salary.
GDS Exception. 335544558. Operation violates CHECK constraint INTEG_30 on view or table EMPLOYEE
At trigger 'CHECK_4'
Error Code: 335544558
SQL State: HY000
The query executed has 1 result columns.
Here are the columns:
FULL_NAME of type VARCHAR
Here are the employee's whose salary < $50,000
Bennet, Ann
Reeves, Roger
Stansbury, Willie
Nordstrom, Carol
O'Brien, Sue Anne
Brown, Kelly
Page, Mary
Parker, Bill
Yanowski, Michael
Green, T.J.
Montgomery, John
Guckenheimer, Mark
Closing database resources and rolling back any changes we made to the database.

Now we try the Jni way (aka using the not so pure driver)
chmod +x libjaybird21.so
Seems to be compiled for 32 bit (i'm on 64 but i have already the lib32 libs)
ldd ./libjaybird21.so 
 linux-gate.so.1 =>  (0xf770d000)
 libdl.so.2 => /lib32/libdl.so.2 (0xf76c7000)
 libc.so.6 => /lib32/libc.so.6 (0xf756d000)
 libstdc++.so.5 => /usr/lib32/libstdc++.so.5 (0xf74b3000)
 /lib/ld-linux.so.2 (0xf770e000)
 libm.so.6 => /lib32/libm.so.6 (0xf748d000)
 libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf7470000)
To run using the compiled interface you need to add the -Djava.library.path when you run the program also change the connection string by adding the native keyword ":native:localhost/3050:"
java -Djava.library.path=. -cp jaybird-full-2.1.6.jar:examples DriverExample
For me it didn't worked because i have a 64bit machine so i need a jaybird source recompilation
libjaybird21.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)

No comments: