我确定我在这里做了一些愚蠢的事情。我正在使用 Ruby 1.9.2-p312、jruby 1.6.8 并将 --1.9 选项设置为默认值。这是我第一次尝试挽救 SQLException。我故意通过拔下以太网连接使这段代码失败。
require 'java'
require 'lib/jt400-6.1'
require 'date'
require 'bigdecimal'
java_import 'com.ibm.as400.access.AS400JDBCDriver'def initialize(parms={})
class DB
def initialize(parms = {})
begin
@connection ||= java.sql.DriverManager.get_connection "jdbc:as400://System/",parms[:user], parms[:pass]
rescue java.sql.SQLException
puts "Error connecting to iSeries. Error code: #{java.sql.SQLException.getErrorCode()}
SQL State: #{java.sql.SQLException.getSQLState()}."
end
end
end
这会产生以下错误:
NoMethodError - undefined method `getErrorCode' for Java::JavaSql::SQLException:Class:
/home/nick/Projects/OrderBridge/app/db.rb:17:in `initialize'
/home/nick/Projects/OrderBridge/app/order-processor.rb:208:in `prepare'
/home/nick/Projects/OrderBridge/app/orderbridge.rb:43:in `POST /advanced'
org/jruby/RubyMethod.java:117:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `compile!'
org/jruby/RubyProc.java:258:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `route!'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in `route_eval'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `route!'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in `process_route'
org/jruby/RubyKernel.java:1226:in `catch'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `process_route'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in `route!'
org/jruby/RubyArray.java:1620:in `each'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `route!'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in `dispatch!'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
org/jruby/RubyKernel.java:1226:in `catch'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/nulllogger.rb:9:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.2/lib/sinatra/showexceptions.rb:21:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/lint.rb:48:in `_call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/lint.rb:36:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/showexceptions.rb:24:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/chunked.rb:43:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
/home/nick/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
/home/nick/.rvm/rubies/jruby-1.6.8/lib/ruby/1.9/webrick/httpserver.rb:111:in `service'
/home/nick/.rvm/rubies/jruby-1.6.8/lib/ruby/1.9/webrick/httpserver.rb:70:in `run'
/home/nick/.rvm/rubies/jruby-1.6.8/lib/ruby/1.9/webrick/server.rb:183:in `start_thread'