1= Programming with SQL Relay using JDBC =
2
3The SQL Relay distribution does not provide a native JBCD driver, but by using the JDBC-ODBC bridge provided by most Java distributions, applications which use JDBC on Unix or Linux may access databases through SQL Relay via the ODBC driver.
4
5Note that the JDBC-ODBC bridge is not available in !OpenJDK and was removed from Oracle Java in version 8.  To use the JDBC-ODBC bridge, you must use Oracle Java 7 or earlier.
6
7See [odbc.html Programming with SQL Relay using ODBC] for instructions detailing how to access SQL Relay through ODBC.  Once that is working, you can access databases through SQL Relay via JDBC as well.
8
9A good program to test this with is [http://henplus.sourceforge.net/ HenPlus], a JDBC command line client.  After downloading and installing !HenPlus, you can run it as follows:
10
11{{{#!blockquote
12'''henplus jdbc:odbc:sqlrexample'''
13}}}
14
15When you run it, you might get an error like:
16
17{{{#!blockquote
18/usr/java/jdk1.7.0_10/bin/java: symbol lookup error: /usr/java/jdk1.7.0_10/jre/lib/i386/libJdbcOdbc.so: undefined symbol: SQLAllocEnv
19}}}
20
21If so, this is because the JDBC-ODBC library wasn't linked properly, a common problem.  It can be fixed by preloading the ODBC driver manager library as follows:
22
23{{{#!blockquote
24export LD_PRELOAD=/usr/lib/libodbc.so
25}}}
26
27(Replacing /usr/lib with the path to libodbc.so on your system)
28
29Here is a sample henplus session:
30
31{{{#!blockquote
32{{{#!code
33[dmuse@fedora bin]$ ./henplus jdbc:odbc:sqlrexample
34no readline found (no JavaReadline in java.library.path). Using simple stdin.
35using GNU readline (Brian Fox, Chet Ramey), Java wrapper by Bernhard Bablok
36henplus config at /home/dmuse/.henplus
37----------------------------------------------------------------------------
38 HenPlus II 0.9.8 "Yay Labor Day"
39 Copyright(C) 1997..2009 Henner Zeller <H.Zeller@acm.org>
40 HenPlus is provided AS IS and comes with ABSOLUTELY NO WARRANTY
41 This is free software, and you are welcome to redistribute it under the
42 conditions of the GNU Public License <http://www.gnu.org/licenses/gpl2.txt>
43----------------------------------------------------------------------------
44HenPlus II connecting
45 url 'jdbc:odbc:sqlrexample'
46 driver version 2.1
47 oracle - Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
48With the Partitioning, OLAP, Data Mining and Real Application Testing options
49@odbc> create table exampletable (col1 int, col2 varchar2(20));
50affected 0 rows (301 msec)
51@odbc> insert into exampletable values (1,'hello');
52affected 1 rows (71 msec)
53@odbc> insert into exampletable values (2,'goodbye');
54affected 1 rows (1 msec)
55@odbc> select * from exampletable;
56------+---------+
57 COL1 |  COL2   |
58------+---------+
59    1 | hello   |
60    2 | goodbye |
61------+---------+
622 rows in result (first row: 56 msec; total: 57 msec)
63@odbc> update exampletable set col2='bye' where col1=2;
64affected 1 rows (2 msec)
65@odbc> select * from exampletable;
66------+-------+
67 COL1 | COL2  |
68------+-------+
69    1 | hello |
70    2 | bye   |
71------+-------+
722 rows in result (first row: 1 msec; total: 2 msec)
73@odbc> delete from exampletable where col1=1;
74affected 1 rows (2 msec)
75@odbc> select * from exampletable;
76------+------+
77 COL1 | COL2 |
78------+------+
79    2 | bye  |
80------+------+
811 row in result (first row: 1 msec; total: 1 msec)
82@odbc> drop table exampletable;
83affected 0 rows (3.637 sec)
84@odbc> quit
85storing settings..
86[dmuse@fedora bin]$
87}}}
88}}}
89
90Similarly, any program that uses JDBC can be configured to use SQL Relay via JDBC by setting its database url to jdbc:odbc:DSN where //DSN// is replaced with the ODBC DSN defined in /etc/odbc.ini.
91
92Developing applications which use JDBC is beyond the scope if this document but many examples and tutorials may be found on the web.
93