-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLite3 No suitable driver #1130
Comments
@ccmywish Your script runs for me. I printed out $: to show what loaded: require 'jdbc/sqlite3'
Jdbc::SQLite3.load_driver
Java::org.sqlite.JDBC
url = "jdbc:sqlite:test.db"
con = java.sql.DriverManager.get_connection url
statement = con.create_statement
statement.execute("create table people (id int PRIMARY_KEY)")
p $:
I also ran this with 9.4. I am using Linux (FC 35). The basic error is also one akin to what you would see in Java itself. If the JDBC driver for sqlite3 is not loaded into your classpath then it will give you a similar error. load_driver just tries to load the .jar file in jdbc-sqlite3. What OS+Java are you using? |
Hi @enebo, Thanks for your help! I'm using JRuby on Windows.
I've changed the script a little to inspect internals: puts require 'jdbc/sqlite3' #=> true
Jdbc::SQLite3.load_driver
Java::org.sqlite.JDBC
url = "jdbc:sqlite:test.db"
p $:
# [
# "C:/PeaceWorkSpace/peace-home/rubylib",
# "C:/Ruby-on-Windows/rbenv/share",
# "C:/Ruby-on-Windows/jruby-9.4.1.0/lib/ruby/gems/shared/gems/jdbc-sqlite3-3.32.3.3/lib", # I've checked this dir, it includes `sqlite-jdbc-3.32.3.3.jar` and `jdbc` directory
# "C:/Ruby-on-Windows/jruby-9.4.1.0/lib/ruby/3.1/site_ruby",
# "C:/Ruby-on-Windows/jruby-9.4.1.0/lib/ruby/stdlib"
# ]
con = java.sql.DriverManager.get_connection url
#=> No suitable driver found for jdbc:sqlite3:test.db (Java::JavaSql::SQLException) You can see, JRuby is still complaining about the driver not found. However, I can run this simpler script (via require 'sequel'
url = "jdbc:sqlite:test.db"
Sequel.connect(url) # Works fine, writes a "test.db" file on the disk. This is why I think it's the cause of my own initialization part using raw |
@ccmywish Interesting. So sequel is using the same gem internally but somehow loading it. I will see if I see anything on Windows but tracing through sequel execution maybe will uncover something? Not sure. |
@ccmywish I tried on windows and it is not loading for me either. The jar file is loading so it doubly confusing. |
Hi there, I also see this issue with: What I am trying to do is to make a connection from Puppet7 custom function to sqlite3 database. As long as Puppet7 is JRuby, I think I need to use JDBC adapters for Active record. So I have Puppet7 server installed and can execure 'irb' in puppetserver environment: irb(main):001:0> require 'jdbc/sqlite3'
=> true
irb(main):002:0> Jdbc::SQLite3.load_driver
=> true
irb(main):003:0> java.sql.DriverManager.registerDriver(org.sqlite.JDBC)
=> nil
irb(main):004:0> database_path ="/infra-db/sqlite.db"
=> "/infra-db/sqlite.db"
irb(main):005:0> connection = java.sql.DriverManager.getConnection("jdbc:sqlite:#{database_path}")
Traceback (most recent call last):
16: from RUBY.<main>(uri:classloader:/META-INF/jruby.home/lib/ruby/gems/shared/gems/irb-1.0.0/exe/irb:11)
15: from org.jruby.RubyKernel$INVOKER$s$rbCatch.call(org/jruby/RubyKernel$INVOKER$s$rbCatch.gen)
14: from org.jruby.RubyKernel.catch(org/jruby/RubyKernel.java:1237)
13: from org.jruby.RubyKernel$INVOKER$s$rbCatch.call(org/jruby/RubyKernel$INVOKER$s$rbCatch.gen)
12: from org.jruby.RubyKernel.catch(org/jruby/RubyKernel.java:1237)
11: from org.jruby.RubyKernel$INVOKER$s$0$0$loop.call(org/jruby/RubyKernel$INVOKER$s$0$0$loop.gen)
10: from org.jruby.RubyKernel.loop(org/jruby/RubyKernel.java:1507)
9: from org.jruby.RubyKernel$INVOKER$s$0$3$eval.call(org/jruby/RubyKernel$INVOKER$s$0$3$eval.gen)
8: from org.jruby.RubyKernel.eval(org/jruby/RubyKernel.java:1091)
7: from org.jruby.RubyKernel.evalCommon(org/jruby/RubyKernel.java:1129)
6: from RUBY.evaluate((irb):5)
5: from org.jruby.javasupport.JavaMethod.invokeStaticDirect(org/jruby/javasupport/JavaMethod.java:369)
4: from org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:457)
3: from java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)
2: from java.sql.DriverManager.getConnection(java/sql/DriverManager.java:270)
1: from java.sql.DriverManager.getConnection(java/sql/DriverManager.java:689)
Java::JavaSql::SQLException (No suitable driver found for jdbc:sqlite:/infra-db/sqlite.db) |
Forgot to mention I am on Centos7 :-) |
Can reproduce the snippet posted in the PR description on MacOS 4.1.1 using jruby |
Hi,
I'm trying this script, but it failed. I've referred to many scripts:
Even the https://rubygems.org/gems/jdbc-sqlite3 description said we only need
Jdbc::SQLite3.load_driver
to load the driver.What am I missing? (I'm not interested using
sequel
oractive_record
now, I just want to try the driver directly). Thanks in advance!The text was updated successfully, but these errors were encountered: