为什么错误 "Uninitialized constant DriverManager" 出现在以前运行的代码中?
Why does the error "Uninitialized constant DriverManager" occur in previously functioning code?
我正在使用 jruby,我正在通过 db2jcc4.jar 文件调用 DB2/BIGSQL 数据库。我在插入和选择时都建立了完美的连接,然后突然间我开始收到错误 "uninitialized constant DriverManager."
文件 db2jcc4.jar 可读且具有正确的权限。我什至回到以前工作的代码的早期版本,我得到了同样的错误。唯一值得注意的变化是服务器重新启动了。
require 'java'
java_import 'com.ibm.db2.jcc.DB2Driver'
java_import 'java.util.Properties'
url = "jdbc:db2://SERVER-REMOVED:PORT_REMOVED/BIGSQL"
output, rset, stmt, conn = nil
begin
properties = java.util.Properties.new
properties['user'] = 'USER REMOVED'
properties['password'] = 'PASSWORD REMOVED'
# Load driver class
driver = DB2Driver.new
DriverManager.registerDriver driver #this comes out to nil
regDrivers = DriverManager.getDrivers
conn = DriverManager.get_connection url, properties
...
知道发生了什么吗?
您可能需要导入 DriverManager class
java_import 'java.sql.DriverManager'
我正在使用 jruby,我正在通过 db2jcc4.jar 文件调用 DB2/BIGSQL 数据库。我在插入和选择时都建立了完美的连接,然后突然间我开始收到错误 "uninitialized constant DriverManager."
文件 db2jcc4.jar 可读且具有正确的权限。我什至回到以前工作的代码的早期版本,我得到了同样的错误。唯一值得注意的变化是服务器重新启动了。
require 'java'
java_import 'com.ibm.db2.jcc.DB2Driver'
java_import 'java.util.Properties'
url = "jdbc:db2://SERVER-REMOVED:PORT_REMOVED/BIGSQL"
output, rset, stmt, conn = nil
begin
properties = java.util.Properties.new
properties['user'] = 'USER REMOVED'
properties['password'] = 'PASSWORD REMOVED'
# Load driver class
driver = DB2Driver.new
DriverManager.registerDriver driver #this comes out to nil
regDrivers = DriverManager.getDrivers
conn = DriverManager.get_connection url, properties
...
知道发生了什么吗?
您可能需要导入 DriverManager class
java_import 'java.sql.DriverManager'