Skip to content

Instantly share code, notes, and snippets.

@samueldana
Created May 21, 2010 20:16
Show Gist options
  • Save samueldana/409360 to your computer and use it in GitHub Desktop.
Save samueldana/409360 to your computer and use it in GitHub Desktop.
import javax.script.*;
import java.io.*;
public class Driver
{
public static void main(String[] args) throws ScriptException, FileNotFoundException, NoSuchMethodException {
// Setup stuff....
// Get the ScriptEngineManager
ScriptEngineManager manager = new ScriptEngineManager();
// Get the JRuby engine
ScriptEngine engine = manager.getEngineByName("jruby");
// Cast the engine to an Invocable
Invocable invocable = (Invocable) engine;
// Get the filename containing our ruby script
String rubyFileName = System.getProperty("user.dir") + "/ruby_script.rb";
// Read in the file
FileReader reader = new FileReader(rubyFileName);
// Evaluate the ruby script
engine.eval(reader);
}
}
require 'rubygems'
gem 'sequel', '>=2.12.0', '<=3.9.0'
require 'sequel'
# Set up DB connection
DB_FILE_NAME = File.expand_path('./SQL.db')
DB = Sequel.connect("jdbc:sqlite:#{DB_FILE_NAME}")
# Simple connectivity test
DB.create_table! :tests do
primary_key :id
end
if DB.table_exists?(:tests)
puts "Finished successfully!"
else
puts "Failed :(" # Doesn't really get here... crashes at line 10
end
#!/bin/bash
javac Driver.java
echo Trying jruby-1.4.0 complete jar
java -cp .:jruby-complete-1.4.0.jar:sqlitejdbc-v056.jar Driver
# => Finished successfully!
echo Trying jruby-1.5.0 complete jar
java -cp .:jruby-complete-1.5.0.jar:sqlitejdbc-v056.jar Driver
# => java/sql/DriverManager.java:602:in `getConnection': NativeException: java.sql.SQLException: No suitable driver found for jdbc:sqlite:/Users/sam/jruby_sqlite_example/SQL.db (Sequel::DatabaseConnectionError)
# from java/sql/DriverManager.java:207:in `getConnection'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/adapters/jdbc.rb:143:in `connect'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/database.rb:86:in `initialize'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/connection_pool.rb:87:in `call'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/connection_pool.rb:87:in `make_new'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/connection_pool/threaded.rb:126:in `make_new'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/connection_pool/threaded.rb:112:in `available'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/connection_pool/threaded.rb:102:in `acquire'
# ... 8 levels...
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/database/schema_methods.rb:73:in `create_table'
# from /Users/sam/.rvm/gems/ruby-1.9.1-p378/gems/sequel-3.9.0/lib/sequel/database/schema_methods.rb:80:in `create_table!'
# from <script>:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment