Hello, ODP.NET(ClojureCLR) World!

Posted on 2月 18th, 2013 by cx20

ODP.NET(ClojureCLR)

ODP.NET(Oracle Data Provider for .NET)は、.NET ベースの Oracle Database 接続用 API である。ODAC(Oracle Data Access Component)と呼ばれるパッケージに含まれる。
.NET 環境での Oracle Database 用データプロバイダとしては、マイクロソフト社が提供する「Microsoft Oracle Client」とオラクル社が提供する「ODP.NET」があるが、現在、「Microsoft Oracle Client」はマイクロソフト社自身が非推奨としており、今後は ODP.NET の使用が推奨されている。

データプロバイダ 説明
System.Data.OracleClient .NET Framework Data Provider for Oracle
Oracle.DataAccess.Client Oracle Data Provider for .NET

ソースコード(ClojureCLR + ODP.NET + Oracle)

(System.Reflection.Assembly/LoadWithPartialName "System.Data")
(System.Reflection.Assembly/LoadWithPartialName "Oracle.DataAccess")
 
(import '(Oracle.DataAccess.Client OracleConnection))
(import '(Oracle.DataAccess.Client OracleCommand))
(import '(Oracle.DataAccess.Client OracleDataReader))
 
(def conStr "Data Source=ORCL;User ID=scott;Password=tiger")
(def sqlStr "SELECT 'Hello, ODP.NET World!' AS Message FROM DUAL")
(def con (OracleConnection. conStr))
(def cmd (OracleCommand. sqlStr con))
(.Open con)
(def reader (.ExecuteReader cmd))
(if (.Read reader)
    (do
        (System.Console/WriteLine (.GetName reader 0))
        (System.Console/WriteLine "---------------------")
        (System.Console/WriteLine (.GetValue reader 0))
    )
)
(.Close reader)
(.Close con)

コンパイル方法

C:¥> Clojure.Main hello.clj

実行結果

MESSAGE
---------------------
Hello, ODP.NET World!

Tags:

Categories: ClojureCLR, ODP.NET

コメントを残す

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

WP-SpamFree by Pole Position Marketing