0

我将 Jruby 和 Rails 3 与jxls一起使用,这是一个在 Excel 中生成报告的 Java 库。

jxls API 有一个 ReportManagerImpl,它在其构造函数中采用 java.sql.Connection。

ReportManager reportManager = new ReportManagerImpl( conn, beans );

在我的非工作代码中,ReportQuery 是一个 ActiveRecord 对象。Jruby 看起来像这样:

conn = ReportQuery.connection
rm = Java::NetSfJxlsReport::ReportManagerImpl.new(conn, params)

但是 ActiveRecord::Base.connection 返回的不是 java.sql.Connection,而是 ActiveRecord::ConnectionAdapters::JdbcAdapter。

如何从 JRuby 访问底层 java.sql.Connection 对象?

我得到的错误信息是:

2012-12-28 17:28:08,000 [main] WARN org.apache.commons.jexl2.JexlEngine - ![3,149]: 'rm.exec('SELECT d.name depname, e.name empname, age, payment, bonus, birthDate FROM employee e, department d where d.id = e.depid order by age desc');' method invocation error org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `createStatement' for #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x13ba673> 
4

1 回答 1

0

采用 。ActiveRecord 连接上的jdbc_connection方法来访问 JRuby 中的原始 JDBC 连接:

ActiveRecord::Base.connection.jdbc_connection
于 2013-01-16T01:30:54.467 回答