Home > Dataroom > News Letter
 
Download
News Letter
Site Link
XpertMon ???? 34?
2007/03/22 10:35 11041


?????. DB2 ? XpertMon ??? ???!
? ????????? DB ??????.
???? ADO.NET? Cloudscape? ??? ????? ?????.
?? ADO.NET? ??, ????? ????, ????? ?? ??? ??????.
?? ??? ??? ?? ????.


ADO.NET and Cloudscape
??
DB2 Run-time Client? ODBC ??? ?? Cloudscape? Derby? ???? ????
???? Java ???? ??? ODBC? ?? C/C++ ?? Perl, .Net ?? ???
???? ??? ? ????.
? ??????? DB2 Run-time Client? ODBC.NET Data Provider? ????
IBM Cloudscape Ver.10.0 ? Apache Derby ??????? ???? ???? ???
???????.

ADO.NET? ADO/OLE DB ?? ????????? ???????. ADO.NET? XML??,
disconnected data access, ??? update control ??? ??? ???????
??? ?? ??? ??? ????? ? ????? ?????.

ADO.NET object model? .NET Data Provider? Data Set?? ??? 'Connected' ?
'Disconnected' ????? ??? ?????.
.NET Data Provider? .NET application? ?? ????? ??? ??? ?????
????, ??? ???? result set ???? ?? ??? ??? ???? ??
connection? ??? ???.

ODBC.NET Data Provider ? ODBC ????? ?? .NET application? ODBC ??? ???
???? ?? ?? ???? ???. IBM ODBC ????? DB2 Run-time Client?
?? ?? ADO.NET? Cloudscape/Derby? ????? ??? ?????. .NET ?????
?? 1.1??, ODBC.NET Data Provider? ?????? ???? ???, namespace?
System.Data.ODBC???.
.NET ????? ?? 1.0???, .NET Data Provider? ??? ???? namespace?
Microsoft.Data.Odbc ???.

Data Set? .NET application? ?? ???? ??? ??? ?????.
application? ?? ???? update? ADO.NET ???? ?? in-memory cache
data set ? ?? ??? ???? ?????.

IBM Cloudscape? ?? ?? ??????? Apache Derby? IBM? ??? ??????.

????? ????
ADO.NET? ???? ?? Cloudscape ? ??? ??? ???.
    - Apache Derby ?? IBM Cloudscape ?? 10.0 ?? ?? ?? - IBM DB2 runtime client ? IBM ODBC Driver ?? 8.2 ?? ?? ?? - .NET Framework Data Providers ? ??????? ??, ?? ??, ?? ???? ?????. - System.Data.Odbc Namespace - .NET Framework Data Provider for ODBC? ???? namespace - DB2 JDBC Universal Driver

??
ODBC.NET Data Provider ? ?? Cloudscape/Derby ?? ADO.NET ??? ???? ????,
??Cloudscape/Derby ??????? ODBC ??? ??? ???? ???.
  1. Cloudscape / Derby ???? ??? ?????.
    java org.apache.derby.drda.NetworkServerControl start

  2. ij ? ?? Cloudscape / Derby ???? ??? ???? ??????? ?????.
    ?? ?? ??? ?? ??? ? ????.
    java org.apache.derby.tools.ij ij> connect 'jdbc:derby:net://localhost:1527/SAMPLEDB; create=true:user=abc;password=abc;';

    ? ???? SAMPLEDB ?? Cloudscape/Derby ??????? ?????.
    ?? ??????? ???? ???? IBM DB2 Universal JDBC Driver for
    Cloudscape/Derby ? ???? ??? ???.
  3. DB2 ???? ?? Cloudscape / Derby ???? ??? DB2 run-time client? ???? ???
    db2 catalog tcpip node CNS remote localhost server 1527 db2 catalog db SAMPLEDB at node CNS authentication server

  4. DB2 ????? ?????? ???.
    db2 connect to SAMPLEDB user abc using abc

  5. ODBC ??? ??? ?????. ODBC ????? ?(DSN) ? ???????
    ???? ?? ????? ???? ????.
    DSN? ODBC Data Source Administrator? ?? ? ?? ???? ?? ? ??? ?????.
    1. ??????? ??? 2000 ?? ??? XP??, ODBC ??? ??? ??? ?????? ??? ? ????.
      ?? -> ?? -> ??? -> ???? -> ??? ??(ODBC) -> ??? DSN

      IBM ODBC Driver? ???? DSN?? ??? ????? ??? ???? ?????.
    2. DB2 ?? ??? ODBC ??? ??? ??? ? ????.
      db2 catalog system odbc data source SAMPLEDB

  6. SAMPLEDB? ?? ODBC ??? ??? ?????? ?????.
    db2 list system odbc data sources

    SAMPLEDB ??? ???? IBM DB2 ODBC DRIVER?? ??? ????? ?????.
    ??? ??????? ?? ???? ?? ??? ?? ???? ??? ????.
    ?? ??, ??? ??????? uncatalog ? ? ?? ??? ??? ????.
    db2 uncatalog node CNS db2 uncatalog db SAMPLEDB

    ODBC? Cloudscape/Derby ??????? ?????? ???? ?? ????
    ODBC ??? ?? ?? ???? SAMPLEDB? ??? ?? ????.
    ??? XP?? ?? ???? ????
    ?? -> ??? -> ???? -> ??? ??(ODBC)?? ?????.
    ??? ?? ODBC ??? ?? ??? ??? ???? ???.
    ?? SAMPLEDB ??? ??? ????? ???? ??? ??? DSN ?? ???? ?
    ???? ? ??? ?? ? ? ????.
    SAMPLEDB ??? ????, ??( C ) ??? ?????.
    ??? ??? ?? ?? ??? ????.


    Cloudscape/Derby ???? ??? localhost?? ???? ???, ??? ID ????
    ?????? ??? ??( C ) ??? ???? Cloudscape/Derby ??????
    SAMPLEDB? ??? ??????. ??? ???? ?? ?? ??? ????.
  7. ?? ??? ????? ??? ??, ODBC .NET Data Provider? ???
    .NET Framework Version 1.1? ?? ????. ?? .NET Framework Version 1.0? ???
    ??? ODBC.NET Data Provider? ??? ???? ??? ???.

Examples
??? ????? ODBC.NET Data Provider? ???? Cloudscape/Derby ???????
???? ??? ?????. ?? C# ????? ????? ????
.NET Framework Version 1.1? ????, C# ????? csc.exe? ??????.
???? ?? ??? ???? Sample1.cs ?? C# ????? ?????
Sample1.exe?? ??? application? ?????.
csc /target:exe Sample1.cs

‘abc’ ?? ??? ID? ????? SAMPLEDB? ?????.
String connString = "DSN=SAMPLEDB;UID=abc;PWD=abc;"; // where datasource name is SAMPLEDB OdbcConnection conn = new OdbcConnection(connString); conn.Open();

?? ?, ????? ??, ?? ? COMMIT ???.
// conn is an OdbcConnection instance
OdbcCommand cmd = conn.CreateCommand(); 
OdbcTransaction trans = conn.BeginTransaction();  // start a transaction
cmd.Transaction = trans;
cmd.CommandText = "UPDATE staff " + " SET salary = (SELECT MIN(salary) " + 
           " FROM staff " + " WHERE id >= 310) " + " WHERE id = 310"; 
cmd.ExecuteNonQuery();  // execute the statement
trans.Commit();    // commit the transaction

???? ????? ??? ? ????.
// conn is an OdbcConnection instance
OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText = "CALL IN_PARAM(?)"; 
 
// Register input parameter for the OdbcCommand 
cmd.Parameters.Add(new OdbcParameter("@p1", OdbcType.Int));
cmd.Parameters[0].Value = 100;
 
// Call the stored procedure 
cmd.ExecuteNonQuery();

?? ??? ?????.
// conn is an OdbcConnection instance
OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT sid, name FROM staff WHERE sid > 100"; 
OdbcDataReader reader = cmd.ExecuteReader();
 
Int32 sid = 0;
String name = ""; 
 
// Output the results of the query
while(reader.Read()) { 
    sid = reader.GetInt32(0);   // first column
    name = reader.GetString(1);   // second column
    Console.WriteLine(" " + sid + " " + name); 
} 
 
reader.Close();

?? ?? Cloudscape/Derby ??????? ???? ???? ???? ????
? ? insert ? ?, ??? fetch?? ???? ?????.
// Note: This C# example uses .NET Framework v1.1
// It connects to a Cloudscape/Derby database named SAMPLEDB.
// It creates a table called staff, inserts 3 rows, then fetches 
// and displays the result set on the console.
 
using System;
using System.Data;
using System.Data.Odbc;
 
namespace IBM.Cloudscape.Samples
{
     class Sample1
     {
          [STAThread]
          static void Main(string[] args)
          {
          //String connString = @"Driver={IBM DB2 ODBC
          //DRIVER};DBALIAS=SAMPLEDB;UID=abc;PWD=abc";  
             String connString = @"DSN=SAMPLEDB;UID=abc;PWD=abc";  // using DSN
             OdbcConnection conn = null;
             OdbcCommand cmd = null;
                     
             Console.WriteLine("Connecting to SAMPLEDB");
 
              try 
              {
                  conn = new OdbcConnection(connString);
 
                  // open database connection
                     conn.Open();
 
                     Console.WriteLine("Connected to SAMPLEDB");
                     
                  // creates a table named staff
                     cmd = new OdbcCommand("CREATE TABLE staff 
                          (sid INT PRIMARY KEY NOT NULL, name VARCHAR(30) 
                           NOT NULL, salary INT NOT NULL)", conn); 
 
                     cmd.ExecuteNonQuery();
 
                     Console.WriteLine("Table staff created");
 
                   // insert data to table staff
                     cmd.CommandText = "INSERT INTO staff VALUES (300, 'John', 35000)";
                     cmd.ExecuteNonQuery();
                            
                     cmd.CommandText = "INSERT INTO staff VALUES (310, 'Mary', 55000)";
                     cmd.ExecuteNonQuery();
                            
                     cmd.CommandText = "INSERT INTO staff VALUES (320, 'Tom', 35000)";
                     cmd.ExecuteNonQuery();
                            
                     Console.WriteLine("3 rows inserted");
 
                   // Fetch data from table staff
                     cmd = new OdbcCommand("SELECT * FROM staff", conn);
                     OdbcDataReader rdr = cmd.ExecuteReader();
 
                     Console.WriteLine("Fetching rows from staff");
 
                     while (rdr.Read())
                     {
                         Console.Write(rdr.GetInt32(0));
                         Console.Write(" " + rdr.GetString(1) + " ");
                         Console.WriteLine(rdr.GetInt32(2));
                     }
 
                         rdr.Close();
 
                     }
                     catch (OdbcException ex) 
                     {
                         int cnt = ex.Errors.Count;
                         for (int i=0; i < cnt; i++) 
                     {
                         Console.WriteLine("Error #" + i + "
" +
                         "Message: " + ex.Errors[i].Message + "
" +
                         "Native: " + ex.Errors[i].NativeError.ToString() + "
" +
                         "SQL: " + ex.Errors[i].SQLState + "
");
                     }
                 }
                     finally 
                     {
                         if (conn != null)
                           conn.Close();
 
                         Console.WriteLine("Sample1 ended");
                     }
              }
       }
}



XpertMon for DB2 UDB V2
DB ???
Tel : 02-2108-1458
Fax : 02-2108-1459
Mobile : 011-896-6545
E-mail : hjlee@iteg.co.kr
URL : http://iteg.co.kr

¡ã XpertMon ???? 35? iteg 2007-03-22 10909
- XpertMon ???? 34? iteg 2007-03-22 11041
¡å XpertMon ???? 33? iteg 2007-03-22 10992
List Write Modify