Not sure if this shouldn't be under java,

or even if anyone will care, but hopefully it will help someone...
Jruby, using JDBC to Apache derby embedded database. I tested this on Linux mint first, then applied it to my pi2b. (took a lot of getting here as it crosses over different documentation paths and is therefore very obscure (was to me anyway!!) lots of research, lots to read.)
I have Java oracle8 version installed. Downloaded the latest jruby (jruby-bin-9.0.0.0.pre2.tar.gz) and Apache derby packages (db-derby-10.11.1.1-bin.tar.gz) (same files on mint
and on rpi).
sudo tar -xvf the packages and moved them to /opt/jruby and /opt/Apache/db-derby-10.11.1.1-bin
Next, added the following to /etc/profile ->
export JRUBY_HOME=/opt/jruby
export PATH=$JRUBY_HOME/bin:$PATH
export DERBY_INSTALL=/opt/Apache/db-derby-10.11.1.1-bin
export CLASSPATH=$DERBY_INSTALL/lib/derby.jar:$DERBY_INSTALL/lib/derbytools.jar:.
(I also copied derbyclient.jar from the lib subdirectory of derby to my ruby directory. See second line of code)
This (probably quite primitive
jruby code now works...)
jruby name.rb
require 'java'
require './derbyclient.jar'
import 'org.apache.derby.jdbc.EmbeddedDriver'
connString = "jdbc:derby:MyGraphDb;create=true"
conn = Java::JavaSql::DriverManager.getConnection(connString)
sql = "CREATE TABLE test (NUM INT PRIMARY KEY, ADDR VARCHAR(12))"
stmt = conn.createStatement()
begin
stmt.execute(sql)
rescue
puts "\n table already exists.\n"
end
stmt.close()
# change the data in the next line to insert different info
sql = "INSERT INTO test values (160, 'silly square')"
stmt = conn.createStatement()
begin
s = stmt.execute_update(sql)
rescue
puts "\n error in insert (duplicate primary key?) \n"
end
stmt.close()
sql = "select * from test"
stmt = conn.createStatement()
rs = stmt.executeQuery(sql)
while (rs.next) do
puts "#{rs.getString("NUM")} -- #{rs.getString("ADDR")}"
end
stmt.close()
conn.close()
puts "\n\n"
It creates the database in your execution directory.
Hope this helps someone. Note that with sqlite3, I failed miserably, because (it said) c based sqlite wasn't supported.
RichR
p.s. I should add: thanks to this links for the major clue that got me there
http://www.tompurl.com/2009/08/21/testi ... ruby-jdbc/