how can i make connecting MS SQL Sever using jruby + Active record?
Env:
jruby 1.5.1 + win xp…
gem installed :
activerecord-sqlserver-adapter-2.3.8.gem
test case:
require “rubygems”
require “active_record”
ActiveRecord::Base.establish_connection(
:adapter => “sqlserver”,
:mode => “odbc”, # or “oda”
:database => “ECARD_WRITE_CARD”,
:host => “10.86.10.26”,
:username => “sa”,
:password => “123456”,
:autocommit => true
)
class Order < ActiveRecord::Base
end
order = Order.find(1)
order.name = “Dave Thomas”
order.save
error:
gem_original_require path
D:/ProgramFiles/jruby-1.5.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
require': no such file to load -- odbc (MissingSourceFile) from D:/ProgramFiles/jruby-1.5.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
require’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in
require' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in
new_constants_in’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in
require' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/kernel/requires.rb:7:in
require_library_or_gem’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/kernel/reporting.rb:11:in
silence_warnings' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/kernel/requires.rb:5:in
require_library_or_gem’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:16:in
sqlserver_connection' ... 15 levels... from D:/Leiking/Study/_Ruby/cmcc/Test/database.rb:15 from D:/Leiking/Study/_Ruby/cmcc/Test/database.rb:1:in
load’
from -e:1
Need install odbc : ODBC Binding for Ruby ??
but from the page above,
I cannot install the gem
when use jruby to install the odbc gem, it gets an error:
D:\ProgramInstall__ProgramDevelopment\Ruby\Gems>jruby -S gem install
ruby-odbc-0.99991.gem
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
Building native extensions. This could take a while…
ERROR: Error installing ruby-odbc-0.99991.gem:
ERROR: Failed to build gem native extension.
d:/ProgramFiles/jruby-1.5.1/bin/jruby.exe extconf.rb
WARNING: JRuby does not support native extensions or the mkmf' library. Check http://kenai.com/projects/jruby/pages/Home for alternatives. extconf.rb:21: undefined method
dir_config’ for main:Object
(NoMethodError)
Gem files will remain installed in
d:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/ruby-odbc-0.99991 for
inspection.
Results logged to
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/ruby-odbc-0.99991/ext/gem_make.out
I find this from jruby site:
however, some Gems build native C libraries as part of their install
process. These Gems will not work in JRuby unless the Gem has also
provided a Java equivalent to the native library.
I cried~~!!!
how can i connect to the f**king sql sever using jruby??? (do not use
activerecord is okay~~… It is a shame…)
wtf!!! wtf windows!!!
what about giving datamapper.org a try. the jruby support is fine -
sqlserver is there via the dm-sqlserver-adapter gem.
regards Kristian
On Thu, Jul 1, 2010 at 5:07 PM, Lei K. [email protected] wrote:
–
Kristian Meier + Saumya Sharma + Sanuka Meier
Vadakkethu House,
Edayanmula West PO - 689532,
Pathanamthitta District, Kerala, INDIA
tel: +91 468 2319577
protect your privacy while searching the net: www.ixquick.com
_=_
q(-_-)p
'_) (_`
/__/ \
_(<_ / )_
(__\_\_|_/__)
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Lei K. wrote:
I find this from jruby site:
however, some Gems build native C libraries as part of their install
process. These Gems will not work in JRuby unless the Gem has also
provided a Java equivalent to the native library.
I cried~~!!!
how can i connect to the f**king sql sever using jruby??? (do not use
activerecord is okay~~… It is a shame…)
wtf!!! wtf windows!!!
Don’t panic!
-
Install the mssql jdbc driver from
http://www.microsoft.com/downloads/details.aspx?familyid=99B21B65-E98F-4A61-B811-19912601FDC9&displaylang=en
-
c:\Documents and Settings\schmrol\Desktop>gem list
*** LOCAL GEMS ***
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activerecord-jdbc-adapter (0.9.7)
activerecord-jdbcsqlite3-adapter (0.9.7)
activeresource (2.3.8)
activesupport (2.3.8, 2.3.5)
authlogic (2.1.5)
bson (1.0.3, 1.0.2)
builder (2.1.2)
columnize (0.3.1)
crack (0.1.7)
durran-validatable (2.0.1)
gem_plugin (0.2.3)
glassfish (1.0.2)
haml (3.0.13, 3.0.12)
jdbc-sqlite3 (3.6.3.054)
jruby-openssl (0.7)
mongo (1.0.3, 1.0.2)
mongo_record (0.5)
mongoid (1.9.1, 1.9.0)
mongrel (1.1.5)
nokogiri (1.4.2)
rack (1.2.1, 1.2.0, 1.1.0)
rails (2.3.8)
rake (0.8.7)
rspec (1.3.0)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3.2)
ruby-debug-ide (0.4.9)
rubygems-update (1.3.7)
savon (0.7.9, 0.7.8)
sources (0.0.1)
weakling (0.0.4)
will_paginate (2.3.14)
- database.yml
JDBC Setup
Adjust JDBC driver URLs as necessary.
development:
adapter: jdbc
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
url:
jdbc:sqlserver://dbhost1;databaseName=CustDB;integratedSecurity=true;
That’s it!
Roland’s answer should get you going,
in case jruby complains about the missing driver you need to make sure
the jar with the driver is on the classpath.
I tend to roll with the new jdbc 4.0 driver that you can get from the
link below.
http://www.microsoft.com/downloads/details.aspx?FamilyID=%20a737000d-68d0-4531-b65d-da0f2a735707&displaylang=en
http://www.microsoft.com/downloads/details.aspx?FamilyID=%20a737000d-68d0-4531-b65d-da0f2a735707&displaylang=en
I copy it to lib directory inside my rails app, and when I need to run
jruby from the console,
I just export the classpath variable with the driver appended to it
|set CLASSPATH=|//%CLASSPATH%;PATH_TO_MSSQL_JAR/sqljdbc4.jar
If by any change you use netbeans to develop, you can add the jar as a
java library on the project configuration,
and everything should run smoothly.
Cheers,
Luis Landeiro R.
Use the activerecord-jdbcmssql-adapter driver with JRuby – JRuby
can’t use the native ODBC driver.
jruby -S gem install activerecord-jdbcmssql-adapter
config/database.yml:
development/test/production:
adapter: jdbcmssql
Cheers,
/Nick
On Thu, Jul 1, 2010 at 6:23 AM, Lei K. [email protected] wrote:
test case:
:autocommit => true
D:/ProgramFiles/jruby-1.5.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
from
`require_library_or_gem’
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
It is also worth mentioning that the jTDS JDBC driver works equally as
well as the Microsoft driver.
http://jtds.sourceforge.net/
On Thu, Jul 1, 2010 at 8:51 AM, Luis R. [email protected]
wrote:
set CLASSPATH=%CLASSPATH%;PATH_TO_MSSQL_JAR/sqljdbc4.jar
activesupport (2.3.8, 2.3.5)
jruby-openssl (0.7)
ruby-debug-base (0.10.3.2)
development:
adapter: jdbc
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
url:
jdbc:sqlserver://dbhost1;databaseName=CustDB;integratedSecurity=true;
That’s it!
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
thanks all,
the jdbc is setup up, but the url is error:
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/active_record/connection_adapters/jdbc_adapter.rb:344:in
initialize': The driver encountered an error: no connection available (RuntimeError) from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/active_record/connection_adapters/jdbc_adapter.rb:476:in
new’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/active_record/connection_adapters/jdbc_adapter.rb:476:in
initialize' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/active_record/connection_adapters/jdbc_adapter.rb:49:in
new’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/active_record/connection_adapters/jdbc_adapter.rb:49:in
jdbc_connection' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/active_record/connection_adapters/jdbc_adapter.rb:56:in
embedded_driver’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/jdbc_adapter/jdbc_mssql.rb:13:in
mssql_connection' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in
new_connection’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in
checkout_new_connection' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in
checkout’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in
loop' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in
checkout’
from D:/ProgramFiles/jruby-1.5.1/lib/ruby/1.8/monitor.rb:191:in
mon_synchronize' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in
checkout’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in
connection' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in
retrieve_connection’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in
retrieve_connection' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in
connection’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:3098:in
quoted_table_name' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1578:in
find_one’
from
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1569:in
find_from_ids' from D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:616:in
find’
from D:/Leiking/Study/_Ruby/cmcc/Test/database.rb:28
the code is :
require ‘rubygems’
require ‘jdbc_adapter’
require ‘active_record’
require “sqljdbc4.jar”
ActiveRecord::Base.establish_connection(:adapter => “jdbcmssql”,
:driver =>
“com.microsoft.sqlserver.jdbc.SQLServerDriver”,
:url =>
“jdbc:jtds:sqlserver://10.86.10.26:1433/ECARD_WRITE_CARD”,
:username=>‘sa’,
:password => “123”
)
class Order < ActiveRecord::Base
end
order = Order.find(1)
order.name = “Dave Thomas”
order.save
I think the url is wrong. Can anyone tell me why ?
thanks!
My database.yml, using jtds and MSSQL
development:
adapter: jdbcmssql
url:
jdbc:jtds:sqlserver://DEV013THKT400:1433/ods_development;instance=MSSMLBIZ;user=ods-application;password=mypass;ssl=request
On Fri, Jul 2, 2010 at 5:16 AM, Luis R. [email protected]
wrote:
 from
`new’
D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/jdbc_adapter/jdbc_mssql.rb:13:in
 from D:/ProgramFiles/jruby-1.5.1/lib/ruby/1.8/monitor.rb:191:in
 from
`find_from_ids’
require ‘jdbc_adapter’
“jdbc:jtds:sqlserver://10.86.10.26:1433/ECARD_WRITE_CARD”,
 host: localhost
To unsubscribe from this list, please visit:
 http://xircles.codehaus.org/manage_email
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
On 07/02/2010 04:06 AM, Lei K. wrote:
from
embedded_driver' D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in D:/ProgramFiles/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in from
find_from_ids’
require ‘active_record’
require “sqljdbc4.jar”
ActiveRecord::Base.establish_connection(:adapter => “jdbcmssql”,
:driver =>
“com.microsoft.sqlserver.jdbc.SQLServerDriver”,
This is the MSSQL driver from Microsoft
:url =>
“jdbc:jtds:sqlserver://10.86.10.26:1433/ECARD_WRITE_CARD”,
Though you are using jtds url instead of MS,
see a database.yml from a rails app that is connected to a sqlserver.
development:
adapter: <%= defined?(JRUBY_VERSION) ? “jdbc” : “mysql” %>
encoding: latin1
reconnect: true
pool: 5
host: localhost
username: bla
password:
database: bla
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://machina\SQLEXPRESS;database=bla
schema: dbo
I think the url is wrong. Can anyone tell me why ?
thanks!
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email