From: Charles Oliver Nutter Date: 2007-12-06T09:48:46+09:00 Subject: Re: Ruby works but not JRuby - when using MySQL Driver Venks wrote: > Yes. Please send me any examples you may have. I already got one from > this mailing-list which I haven't tried yet. But don't mind receiving > few from you. > > At this stage, JDBC seems to like the best option given that I need to > to communicate 2 different databases and one of them has only JDBC > interface and other is MySQL for which I will use JDBC too. Since JDBC > is my only option, JRuby will be the default choice. Here's a very simple example to get you into the JDBC frame of mind. This is basically a portion of the code shown at http://www.cs.unc.edu/Courses/comp118/docs/lessons/java/java_jdbc/jdbcServletMysql.html ...translated to Ruby. url = "jdbc:mysql://sparrow.cs.unc.edu/jbsdb" query = "SELECT * FROM Person WHERE owner = 'jbs'" begin Java::com.mysql.jdbc.Driver # make sure driver class is loaded conn = java.sql.DriverManager.get_connection( url, "your_mysgl_login", "your_mysql_password") stmt = con.create_statement rs = stmt.execute_query (query) print_result_set(resp, rs) ensure rs.close stmt.close conn.close end JDBC is a pretty clean API, and even cleaner in Ruby. - Charlie