Hello, Connector/NET(IronRuby) World!

Posted on 4月 8th, 2013 by cx20

Connector/NET(IronRuby)

Connector/NET は、.NET ベースの MySQL 接続用 API である。
以下は IronRuby による Connector/NET ライブラリを使用した MySQL への接続例となっている。

ソースコード(IronRuby + Connector/NET + MySQL)

require 'mscorlib'
require 'System'
require 'MySql.Data'
include System
include MySql::Data::MySqlClient
 
conStr = "server=localhost;user id=root;password=P@ssW0rd"
sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
 
con = MySqlConnection.new(conStr)
cmd = MySqlCommand.new(sqlStr, con)
con.Open()
 
reader = cmd.ExecuteReader()
while reader.Read() do
    Console.WriteLine( reader.GetName(0) )
    Console.WriteLine( "---------------------" )
    Console.WriteLine( reader.GetValue(0) )
end
 
reader.Close()
con.Close()

実行方法

C:¥> ir Hello.rb

実行結果

MESSAGE
---------------------
Hello, Connector/NET World!

Tags:

Categories: Connector/NET, IronRuby

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

WP-SpamFree by Pole Position Marketing