スケーラブルデータベースサーバ HiRDB Version 8 UAP開発ガイド
表exにデータ「1」を挿入する例を次に示します。
using System;
using System.Data;
using Hitachi.HiRDB;
namespace test_C
{
class Sample
{
[STAThread]
static void Main(string[] args)
{
// Connectionオブジェクトを作成する
HiRDBConnection cn = new HiRDBConnection("dsn=pc;");
// DBに接続する
cn.Open();
// Transactionオブジェクトを作成する
HiRDBTransaction tran;
// トランザクション開始
tran = cn.BeginTransaction(IsolationLevel.ReadCommitted); ..1
// Commandオブジェクトを作成する
HiRDBCommand cm = new HiRDBCommand();
cm.Connection = cn;
cm.Transaction = tran;
try
{
// 表にデータを挿入する
cm.CommandText = "insert into ex values (1)";
cm.ExecuteNonQuery();
// トランザクション成功
tran.Commit(); .........................................2
// DBから切断する
cn.Close();
}
catch ( HiRDBException ex)
{
// トランザクション失敗
tran.Rollback(); .......................................3
Console.WriteLine(ex);
}
catch ( System.Exception ex)
{
// トランザクション失敗
tran.Rollback(); .......................................3
Console.WriteLine(ex);
}
}
}
}
|
Imports System
Imports System.Data
Imports Hitachi.HiRDB
Module Module1
Sub Main()
Dim cn As HiRDBConnection
Dim tran As HiRDBTransaction
Dim cm As HiRDBCommand
' Connectionオブジェクトを作成する
cn = New HiRDBConnection("dsn=pc;")
' DBに接続する
cn.Open()
' トランザクション開始
tran = cn.BeginTransaction(IsolationLevel.ReadCommitted) .......1
' Commandオブジェクトを作成する
cm = New HiRDBCommand()
cm.Connection = cn
cm.Transaction = tran
Try
' 表にデータを挿入する
cm.CommandText = "insert into ex values (1)"
cm.ExecuteNonQuery()
' トランザクション成功
tran.Commit() ..............................................2
' DBから切断する
cn.Close()
Catch ex As HiRDBException
' トランザクション失敗
tran.Rollback() ............................................3
Console.WriteLine(ex)
Catch ex As System.Exception
' トランザクション失敗
tran.Rollback() ............................................3
Console.WriteLine(ex)
End Try
End Sub
End Module
|
All Rights Reserved. Copyright (C) 2006, 2016, Hitachi, Ltd.