Archive for the ‘Connector/NET’ Category

  1. Hello, Connector/NET(F#) World!

    Posted on 4月 5th, 2013 by cx20

    Connector/NET(F#)

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

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

    open System;
    open MySql.Data.MySqlClient;
     
    let conStr = "server=localhost;user id=root;password=P@ssW0rd"
    let con = new MySqlConnection(conStr)
    let sqlStr = "SELECT 'Hello, Connector/NET World' AS Message"
    let cmd = new MySqlCommand(sqlStr, con)
    con.Open()
    let reader = cmd.ExecuteReader()
    while reader.Read() do
        printfn "%s" (reader.GetName(0))
        printfn "---------------------" 
        printfn "%s" (reader.GetString(0))
    reader.Close()
    con.Close()

    コンパイル方法

    C:¥> fsc Hello.fs -r:MySql.Data.dll

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  2. Hello, Connector/NET(JScript.NET) World!

    Posted on 4月 4th, 2013 by cx20

    Connector/NET(JScript.NET)

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

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

    import System;
    import System.Data;
    import System.Drawing;
    import MySql.Data.MySqlClient;
     
    main();
     
    function main() {
        var conStr = "server=localhost;user id=root;password=P@ssW0rd";
        var sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message";
     
        var con = new MySqlConnection(conStr);
        var cmd = new MySqlCommand(sqlStr, con);
        con.Open();
        var reader = cmd.ExecuteReader();
        while( reader.Read() )
        {
            Console.WriteLine( reader.GetName(0) );
            Console.WriteLine( "---------------------" );
            Console.WriteLine( reader[0] );
        }
        reader.Close();
        con.Close();
    }

    コンパイル方法

    C:¥> jsc /r:MySql.Data.dll Hello.js

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  3. Hello, Connector/NET(C++/CLI) World!

    Posted on 4月 3rd, 2013 by cx20

    Connector/NET(C++/CLI)

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

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

    #using <System.dll>
    #using <System.Data.dll>
    #using <MySql.Data.dll>
     
    using namespace System;
    using namespace MySql::Data::MySqlClient;
     
    int main( array<System::String^>^ args )
    {
        String^ conStr = "server=localhost;user id=root;password=P@ssW0rd";
        String^ sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message";
     
        MySqlConnection^ con = gcnew MySqlConnection(conStr);
        MySqlCommand^ cmd = gcnew MySqlCommand(sqlStr, con);
        con->Open();
        MySqlDataReader^ reader = cmd->ExecuteReader();
        while( reader->Read() )
        {
            Console::WriteLine( reader->GetName(0) );
            Console::WriteLine( "---------------------" );
            Console::WriteLine( reader[0] );
        }
        reader->Close();
        con->Close();
     
       return 0;
    }

    コンパイル方法

    C:¥> SET LIBPATH=C:\Program Files (x86)\MySQL\Connector NET 6.5.4\Assemblies\v2.0;%LIBPATH%
    C:¥> cl Hello.cpp /clr

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  4. Hello, Connector/NET(VB.NET) World!

    Posted on 4月 2nd, 2013 by cx20

    Connector/NET(VB.NET)

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

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

    Imports System
    Imports MySql.Data.MySqlClient
     
    Class Hello
        Shared Sub Main()
            Dim conStr As String = "server=localhost;user id=root;password=P@ssW0rd"
            Dim sqlStr As String = "SELECT 'Hello, Connector/NET World!' AS Message"
     
            Dim con As MySqlConnection = New MySqlConnection(conStr)
            Dim cmd As MySqlCommand = New MySqlCommand(sqlStr, con)
            con.Open()
            Dim reader As MySqlDataReader = cmd.ExecuteReader()
            While reader.Read()
                Console.WriteLine( reader.GetName(0) )
                Console.WriteLine( "---------------------" )
                Console.WriteLine( reader(0) )
            End While
            reader.Close()
            con.Close()
        End Sub
    End Class

    コンパイル方法

    C:¥> vbc /r:MySql.Data.dll Hello.vb

    実行結果

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

    Posted on 4月 1st, 2013 by cx20

    Connector/NET

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

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

    using System;
    using MySql.Data.MySqlClient;
     
    class Hello
    {
        static void Main( String[] args )
        {
            string conStr = "server=localhost;user id=root;password=P@ssW0rd";
            string sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message";
     
            MySqlConnection con = new MySqlConnection(conStr);
            MySqlCommand  cmd = new MySqlCommand(sqlStr, con);
            con.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            while( reader.Read() )
            {
                Console.WriteLine( reader.GetName(0) );
                Console.WriteLine( "---------------------" );
                Console.WriteLine( reader[0] );
            }
            reader.Close();
            con.Close();
        }
    }

    コンパイル方法

    C:¥> csc /r:MySql.Data.dll Hello.cs

    実行結果

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