I’m testing a web application with ruby 1.8.7 and WATiR and I’d like to connect to a H2 database as easily as possible, which I can only find info on JDBC access for. If there’s a way to use JRuby to do this from Ruby that is okay, but I need to use Ruby primarily because my WATiR code is written in it and will hopefully remain so.
All possible solutions will be considered but I’m looking for some simplicity because my database knowledge is limited and I need to access the database (read from and write to) from Ruby/WATiR to test against what’s displayed on the web front end.
EDIT: I removed some of my ignorance, now I know JDBC is a Java API for DB access, so I’m now looking for any way to connect to a H2 database so that my Ruby/WATiR scripts can access it.
Background:
I have some experience with DBI and Sequel gems, and I have Rails installed (so I can start to play with ActiveRecord, mainly), but willing to learn new things to solve this issue.
Let’s assume I’m not a great Java coder. I’ve also never looked into using JRuby before, so I’m not entirely familiar with how it works.
Solution
I eventually got the two talking to each other, mainly thanks to Thomas Mueller’s answer below. I installed the PostgreSQL ODBC driver, got Sequel working and connected using ODBC. Using Sequel’s PG adapter to connect to the H2 PG server causes some Syntax errors that I’m still working on. I have not yet tried DBI to connect, but I will as it may give me greater control of the syntax should I need it. Many thanks also to Jeremy Evans for his help solving a conflict between activerecord-jdbc-adapter and Sequel (pesky pg.rb file in my ruby path), and for managing Sequel. This is not listed as an answer so that I can give credit to those that answered whilst giving feedback to people in the same situation as me.
I have installed pg (not ruby-pg), sequel, dbi, dbd-odbc (plus a manual file fix, you can ask me for details), hoe, and UNinstalled activerecord-jdbc-adapter.
H2 can act as a PostgreSQL server and supports the PostgreSQL ODBC driver.
So in theory you should be able to use ruby-pg. But I have never tried it myself, I guess the chances that it works are about 50%. So the answer is: maybe. But the preferred solution is to use JRuby.
If WATiR is written in Ruby… then WATiR should also work in JRuby?