Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to connect to a DB2 database.

Reply
Thread Tools

How to connect to a DB2 database.

 
 
Victor Reyes
Guest
Posts: n/a
 
      10-28-2004
Hello Ruby world.
The platform:

ruby 1.8.2 (2004-07-29) [i386-mswin32]
Windows/XP
DB2 8.1.4
DBname = dvddbase

The questions:

1 - How do I talk (connect) to a DB2 database using Ruby?
2 - Any sample code that can be shared?

Thank you

Victor


 
Reply With Quote
 
 
 
 
Michael Neumann
Guest
Posts: n/a
 
      10-28-2004
On Fri, Oct 29, 2004 at 12:28:26AM +0900, Victor Reyes wrote:
> Hello Ruby world.
> The platform:
>
> ruby 1.8.2 (2004-07-29) [i386-mswin32]
> Windows/XP
> DB2 8.1.4
> DBname = dvddbase
>
> The questions:
>
> 1 - How do I talk (connect) to a DB2 database using Ruby?
> 2 - Any sample code that can be shared?


You need Ruby/DBI and Ruby/DB2. See RAA (raa.ruby-lang.org).
http://ruby-dbi.rubyforge.org

A simple example:

require 'dbi'

DBI.connect('dbiB2:dvddbase', 'username', 'password') do |dbh|
p dbh.select_all('SELECT * FROM table')
end

Hope this helps.

Regards,

Michael


 
Reply With Quote
 
 
 
 
Victor Reyes
Guest
Posts: n/a
 
      10-28-2004
I noticed that I already have dbi installed as part of the 1.8.2 installation.
However, when I try to use it to test it, I get the following errors:

C:\Program Files\IBM\SQLLIB\BIN>ruby db2c.rb
C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:499:in `load_driver': is
not a class/module (TypeError)
from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver'
from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect'
from db2c.rb:5

Any idea?

Thank you


 
Reply With Quote
 
Michael Neumann
Guest
Posts: n/a
 
      10-28-2004
On Fri, Oct 29, 2004 at 01:22:59AM +0900, Victor Reyes wrote:
> I noticed that I already have dbi installed as part of the 1.8.2 installation.
> However, when I try to use it to test it, I get the following errors:
>
> C:\Program Files\IBM\SQLLIB\BIN>ruby db2c.rb
> C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:499:in `load_driver': is
> not a class/module (TypeError)
> from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver'
> from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect'
> from db2c.rb:5
>
> Any idea?


Yes, you have to install Ruby/DB2, too

Regards,

Michael


 
Reply With Quote
 
Victor Reyes
Guest
Posts: n/a
 
      10-28-2004
Mike,
Thank you for your help so far.
The new problem now is installing Ruby/DB2.

Right from the beginning I have a problem. the "export" command does
not work under windows/XP. Second, even when I set the DB2DIR
environmental variable via the "set" command, it still does not work.

C:\$user\ruby\ruby-db2-0.4>export DB2DIR=C:/db2/SQLLIB/
'export' is not recognized as an internal or external command,
operable program or batch file.

C:\$user\ruby\ruby-db2-0.4>

or using the "set" command, which appears to work:

C:\$user\ruby\ruby-db2-0.4>set DB2DIR=C:/db2/SQLLIB/

C:\$user\ruby\ruby-db2-0.4>

C:\$user\ruby\ruby-db2-0.4>ruby setup.rb config
setup.rb:714: warning: don't put space before argument parentheses
entering config phase...
config done.

C:\$user\ruby\ruby-db2-0.4>

C:\$user\ruby\ruby-db2-0.4>ruby setup.rb setup
setup.rb:714: warning: don't put space before argument parentheses
entering setup phase...
C:/Ruby/bin/ruby extconf.rb
checking for SQLConnect() in db2cli.lib... no
ABORT: Could not locate DB2 libraries or headers!
Please set DB2DIR to your DB2 directory, e.g. /usr/IBMdb2/V7.1 (UNIX)
or C:/SQLLIB (Windows)
setup failed
'system C:/Ruby/bin/ruby extconf.rb' failed
try "ruby setup.rb --help" for usage

C:\$user\ruby\ruby-db2-0.4>

Question:

Is there a windows/xp binary that can be downloaded? or any idea about
this new road-block?

Thank you

Victor


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
DB2 under Windows XP - "Missing DB2 Libraries or headers" daf@jaade.com Ruby 0 04-26-2006 03:08 PM
Installing ruby-db2-0.4 for DB2 gives SQLConnect() errors. Dinesh Ruby 0 04-03-2006 04:20 AM
Hibernate 3.1 and db2 connecting using com.ibm.db2.jcc.DB2Driver crawstevenford@gmail.com Java 0 02-19-2006 08:20 PM
connect to db2 database using dbi? Kate Perry Perl 0 07-10-2003 06:44 PM



Advertisments