Professional Web Applications Themes

Calling JDBC from with Ruby - Ruby

I am building a web application for a client in Ruby. The application is working but now needs to access data using JDBC. My client is requiring both ODBC (for Windows) and JDBC (for Sun) access to data. I am looking for an example of how to use JDBC from within Ruby. I have looked at Jruby but would prefer to write my own code rather than rely on a third party add-on that is beta, especially one that has not been updated in a while. If I write the data access portion in Java that uses JDBC, can I ...

  1. #1

    Default Calling JDBC from with Ruby

    I am building a web application for a client in Ruby. The application is working but now needs to access data using JDBC. My client is requiring both ODBC (for Windows) and JDBC (for Sun) access to data. I am looking for an example of how to use JDBC from within Ruby. I have looked at Jruby but would prefer to write my own code rather than rely on a third party add-on that is beta, especially one that has not been updated in a while. If I write the data access portion in Java that uses JDBC, can I then write a Java wrapper that would allow Ruby to call the Java methods? Are there any examples available showing how to call a Java method from within Ruby similar to the C interface to Ruby?

    If I can't come up with a viable solution to accessing JDBC soon, I may have to re-write it in Java.

    Thanks in advance,
    Michael Davis
    Michael Guest

  2. #2

    Default Re: Calling JDBC from with Ruby

    On Saturday, February 21, 2004, 12:59:51 PM, Michael wrote, in part:
     

    If I may go out on a limb here, I've never heard anything so
    ridiculous. I mean, that's clients for you, but isn't it sufficient
    that the application should just "access data"?

    Anyway, someone please prove me wrong, but you can't "access JDBC with
    Ruby". JDBC must be accessed through a JVM, so JRuby might be your
    only hope.

    Gavin




    Gavin Guest

  3. #3

    Default Re: Calling JDBC from with Ruby

    "Gavin Sinclair" wrote: 
    >
    > If I may go out on a limb here, I've never heard anything so
    > ridiculous. I mean, that's clients for you, but isn't it sufficient
    > that the application should just "access data"?
    >
    > Anyway, someone please prove me wrong, but you can't "access JDBC with
    > Ruby". JDBC must be accessed through a JVM, so JRuby might be your
    > only hope.[/ref]

    Yes. JDBC is ODBC for Java and Java only. I suppose one could call the
    ODBC interface for Ruby, RDBC; but thankfully they didn't decide to that
    and confuse the issue. ;-)

    --
    J. Lambert




    Jon Guest

  4. #4

    Default Re: Calling JDBC from with Ruby


    "Michael Davis" <com> schrieb im Newsbeitrag
    news:YWyZb.1830$news.pas.earthlink.net... 
    is 

    This sounds strange to me. Didn't you mean to say "the application needs
    to access data in a relational database"? In that case DBI is your
    friend. No need for JDBC here.

    Regards

    robert

    Robert Guest

  5. #5

    Default Re: Calling JDBC from with Ruby

    Robert Klemme wrote:
     
    >
    > is

    >
    >
    > This sounds strange to me. Didn't you mean to say "the application needs
    > to access data in a relational database"? In that case DBI is your
    > friend. No need for JDBC here.
    >
    > Regards
    >
    > robert
    >[/ref]

    No. The data that I need to access may not always be relational and I have been given specific requirements for using both JDBC and ODBC. I explored many possible options for accessing data with my client and they have several very good reasons for these requirements.

    Thanks, Michael
    Michael Guest

  6. #6

    Default Re: Calling JDBC from with Ruby


    "Michael Davis" <com> schrieb im Newsbeitrag
    news:AKo_b.4954$news.pas.earthlink.net... 
    > >
    > > is
    > > 
    > >
    > >
    > > This sounds strange to me. Didn't you mean to say "the application[/ref][/ref]
    needs 
    >
    > No. The data that I need to access may not always be relational and I[/ref]
    have been given specific requirements for using both JDBC and ODBC. I
    explored many possible options for accessing data with my client and they
    have several very good reasons for these requirements. 

    I guess, you'll have a hard time convincing Ruby to use JDBC but I've
    successfully drawn data from an ODBC data source with the windows build of
    Ruby. (Note: this is not the cygwin build but the MS C++ build)

    Regards

    robert

    Robert Guest

  7. #7

    Default Re: Calling JDBC from with Ruby


    "Michael Davis" <com> wrote in message
    news:AKo_b.4954$news.pas.earthlink.net...

    {snip...}
     
    have been given specific requirements for using both JDBC and ODBC. I
    explored many possible options for accessing data with my client and they
    have several very good reasons for these requirements. 

    I'm curious as to your current thinking on this. Are you considering a
    separate Java process to mediate between Ruby requests and JDBC calls? (Not
    suggesting anything; I'm in uncharted waters here. Just nosy :-)

    - dan


    dhtapp Guest

  8. #8

    Default Re: Calling JDBC from with Ruby

    dhtapp wrote:
     
    >
    > have been given specific requirements for using both JDBC and ODBC. I
    > explored many possible options for accessing data with my client and they
    > have several very good reasons for these requirements.

    >
    >
    > I'm curious as to your current thinking on this. Are you considering a
    > separate Java process to mediate between Ruby requests and JDBC calls? (Not
    > suggesting anything; I'm in uncharted waters here. Just nosy :-)
    >
    > - dan
    >
    >[/ref]

    Thanks. I offered the original question because I am also unclear about what choices I have. Having a separate Java process running that my Ruby application would talk too for JDBC access is worth considering, however, I am concerned about my clients willingness to supporting an additional process that must always be running.

    I am also considering using JRuby as Gavin suggested but I am concerned about my clients willingness to accept using a third party utility that is still in beta and their ability to support the product after I have developed it for them.

    I am comfortable with creating a C module that allows Ruby to access other existing libraries. This is the approach I am planning to use for ODBC access. However, I don't know if it is even possible to create a Ruby extension using C or Java that would allow me access to JDBC.

    In the end, I want to deliver the simplest, easiest to support solution I possibly can. I feel I have achieved this using Ruby with the one exception of needing to support JDBC. If adding JDBC means using an approach that too difficult to support, I will have to re-write using Java.

    Thanks, Michael
    Michael Guest

  9. #9

    Default Re: Calling JDBC from with Ruby

    Michael Davis wrote:
     
    >>
    >>
    >> have been given specific requirements for using both JDBC and ODBC. I
    >> explored many possible options for accessing data with my client and they
    >> have several very good reasons for these requirements.[/ref][/ref]

     

    Yuk.

    Have I missed something here? JDBC is a SQL driver. Why don't you just
    use Rubys SQL support to talk to the database.

    I know you said it has 'good reasons' to be JDBC - is that because
    there is some custom db that only has a jdbc / odbc facade?
    If you can't say, fair enough.





    Dick Guest

  10. #10

    Default Re: Calling JDBC from with Ruby

    Hi,

    From: "Michael Davis" <com>
     

    Have you seen the threads in ruby-talk about rjni ?
    http://ruby-talk.org/75068
    http://ruby-talk.org/90798

    (rjni home page: http://thekode.net/ruby/rjni/ )


    Even though rjni is said to be in "at best Alpha" stage of
    development, I was guessing that what you're trying to do
    might be a subset of what rjni does, and perhaps the code
    there might make a useful starting point for you? (Or parts
    of the code useful for you to adapt?)


    Hope this helps,

    Regards,

    Bill




    Bill Guest

  11. Moderated Post

    Default Re: Calling JDBC from with Ruby

    Removed by Administrator
    Michael Guest
    Moderated Post

  12. #12

    Default Re: Calling JDBC from with Ruby


    "Michael Davis" <com> schrieb im Newsbeitrag
    news:Onq_b.5102$news.pas.earthlink.net... 
    existing libraries. 
    don't know if it is even 
    access to JDBC.

    You don't need to do that, DBI has this ability already on Windows.

    robert

    Robert Guest

  13. #13

    Default Re: Calling JDBC from with Ruby

    Robert Klemme wrote:
     
    >
    > existing libraries.

    >
    > don't know if it is even

    >
    > access to JDBC.
    >
    > You don't need to do that, DBI has this ability already on Windows.
    >
    > robert
    >[/ref]

    I trust you are referring to DBI's ability to use ODBC in Windows. I am aware of this and if my requirement were to only to access data using ODBC on Windows, I would strongly consider using DBI. However, this does not address my need to access data using JDBC in a unix environment.

    Thanks, Michael
    Michael Guest

  14. #14

    Default Re: Calling JDBC from with Ruby

    Michael Davis <com> wrote in message news:<AKo_b.4954$news.pas.earthlink.net>... 

    Are you trying to cheat? The only reason I can think of for
    *requiring* an application to use JDBC is to be obtuse about
    *requiring* the application to be written in Java.

    However silly your requirements may sound, it seems to me as if you
    have four options:

    1) Write a dumb Java application that takes two arguments: a JDBC
    connection string, and a SQL string. Then have it execute the query
    and dump the results as a [CT]SV and have your Ruby application invoke
    the Java app to get the data. This is really, really stupid.
    2) Use JRuby to execute your application. Then you can access the
    JDBC API from within Ruby. This is a better solution, but your
    application will be that much slower, and you'll have to be careful
    about the places where JRuby is incomplete.
    3) Implement (1), but secretly, and obtusely, use the Ruby DBI
    interface.
    4) Shoot the person who gave you that requirement, because it is
    utterly stupid*.



    * I can think of only one case in which you *have* to use JDBC, and
    that would be where you happen to have a JDBC connector for a
    database, and one doesn't exist for DBI. Improbable, but possible.

    --- SER
    Sean Guest

  15. #15

    Default Re: Calling JDBC from with Ruby

    On 24/02/2004, at 2:15 AM, Michael Davis wrote: 

    If JDBC is an absolute requirement, I'd say be pragmatic, roll up your
    sleeves, take a deep breath and use Java. Hack the whole thing in Java
    with JDBC, and use Java's JDBC-ODBC bridge for the ODBC. A
    multi-language solution would be an interesting exercise, but it would
    end up being an order of magnitude more fragile and less maintainable.

    It's one of those situations where you have to put aside personal
    preference and use the appropriate tool for the job.

    Charles Miller

    --
    Contributing to the heat death of the Universe since 1975
    org http://fishbowl.pastiche.org



    Charles Guest

  16. #16

    Default Re: Calling JDBC from with Ruby

    Sean Russell wrote:
     
    >
    >
    > Are you trying to cheat? The only reason I can think of for
    > *requiring* an application to use JDBC is to be obtuse about
    > *requiring* the application to be written in Java.
    >
    > However silly your requirements may sound, it seems to me as if you
    > have four options:
    >
    > 1) Write a dumb Java application that takes two arguments: a JDBC
    > connection string, and a SQL string. Then have it execute the query
    > and dump the results as a [CT]SV and have your Ruby application invoke
    > the Java app to get the data. This is really, really stupid.
    > 2) Use JRuby to execute your application. Then you can access the
    > JDBC API from within Ruby. This is a better solution, but your
    > application will be that much slower, and you'll have to be careful
    > about the places where JRuby is incomplete.
    > 3) Implement (1), but secretly, and obtusely, use the Ruby DBI
    > interface.
    > 4) Shoot the person who gave you that requirement, because it is
    > utterly stupid*.
    >
    >
    >
    > * I can think of only one case in which you *have* to use JDBC, and
    > that would be where you happen to have a JDBC connector for a
    > database, and one doesn't exist for DBI. Improbable, but possible.
    >
    > --- SER[/ref]

    1) I hadn't considered this possibility. Thanks for suggesting it.

    2) I am considering this possibility but I have some reservations in addition to the ones you mention.

    3) I am not even going to consider this option, it's an integrity thing. I am always up front with my clients about how things are implemented.

    4) Is it wise to to jump to such a conclusion without first fully understanding all of the reasons for such a requirement? I understand my clients need for JDBC and while it may not make since given the limited information I have provided, it does make a lot of since to my client.

    May I lovingly add, that criticism about my clients requirement(s) is not really very helpful. I have a requirement and I intend to satisfy all of the requirements. I am looking for a solution not reasons why I shouldn't do it.

    Thanks, Michael
    Michael Guest

  17. #17

    Default Re: Calling JDBC from with Ruby

    Michael Davis wrote:

    .... 
    ...

    did you consider some sort of http-based facade for accessing your JDBC only
    database - e.g. via SOAP ?

    markus

    Markus Guest

  18. #18

    Default Re: Calling JDBC from with Ruby

    Markus Spath wrote: 
    >
    > ..
    >
    > did you consider some sort of http-based facade for accessing your JDBC
    > only database - e.g. via SOAP ?
    >
    > markus
    >[/ref]

    Interesting suggestion but I'm not sure I understand. Would you mind offering a little more detail about what would be needed to set up the http-based facade?

    Thanks, Michael
    Michael Guest

  19. #19

    Default Re: Calling JDBC from with Ruby

    Michael Davis wrote:
     

    probably overengineered: encapsulating the jdbc database as a web service:

    * a servlet-container (e.g. Tomcat)
    * a java library for 'web services' / SOAP (e.g. Axis
    http://ws.apache.org/axis/java/user-guide.html)
    * a servlet that translates the Requests into the proper JDBC statements and
    generates the Response
    * a Ruby library for SOAP

    alternatively you could build your own micro server in java that listens on
    some port and provides the business logic for accessing the database.

    just some thoughts,
    markus

    Markus Guest

  20. #20

    Default Re: Calling JDBC from with Ruby


    "Michael Davis" <com> schrieb im Newsbeitrag
    news:xqB_b.7169$news.pas.earthlink.net... [/ref][/ref]
    understand [/ref][/ref]
    my 
    > >
    > > ..
    > >
    > > did you consider some sort of http-based facade for accessing your[/ref][/ref]
    JDBC 
    >
    > Interesting suggestion but I'm not sure I understand. Would you mind[/ref]
    offering a little more detail about what would be needed to set up the
    http-based facade?

    I guess he means, write a small web application (basically a single
    Servlet that executes queries and returns the result), deploy it in Tomcat
    (or any other Servlet Container) and have your Ruby script contact that
    servlet via HTTP, transferring the query and receiving the result as CSV,
    HTML, XML or whatever. That's basically a variant of option 1 (java
    command line executable) which should perform better since you don't have
    the startup-connect-disconnect-shutdown penalty you have to pay with a
    command line tool.

    That's probably the cleanest and most performant solution if HTTP is
    allowed by your clients. It's a simple web service, if you like, but
    without the need for SOAP.

    Regards

    robert

    Robert Guest

Page 1 of 2 12 LastLast

Similar Threads

  1. calling ruby methods in C
    By Charles in forum Ruby
    Replies: 2
    Last Post: January 19th, 07:29 PM
  2. Replies: 0
    Last Post: November 1st, 05:21 PM
  3. Replies: 1
    Last Post: October 29th, 07:52 PM
  4. Ruby-dl problem: calling func with param
    By Robert Feldt in forum Ruby
    Replies: 8
    Last Post: September 8th, 12:00 PM
  5. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
    By guillaume.pierronnet@ratp.fr in forum Ruby
    Replies: 0
    Last Post: August 31st, 11:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139