Hello, Connector/NET(IronPython) World!

Posted on 4月 7th, 2013 by cx20

Connector/NET(IronPython)

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

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

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

実行方法

C:¥> ipy Hello.py

実行結果

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

Tags:

Categories: Connector/NET, IronPython

コメントを残す

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

WP-SpamFree by Pole Position Marketing