MFC 환경에서 ODBC를 활용한 Oracle 데이터베이스 접속MFC 환경에서 ODBC를 활용한 Oracle 데이터베이스 접속

Posted at 2011. 12. 11. 03:48 | Posted in 카테고리 없음


01.// ODBCConsole.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
02.//
03. 
04.#include "stdafx.h"
05.#include "ODBCConsole.h"
06. 
07.#ifdef _DEBUG
08.#define new DEBUG_NEW
09.#endif
10. 
11. 
12.// 유일한 응용 프로그램 개체입니다.
13. 
14.CWinApp theApp;
15. 
16.using namespace std;
17. 
18.int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
19.{
20.    int nRetCode = 0;
21. 
22.    // MFC를 초기화합니다. 초기화하지 못한 경우 오류를 인쇄합니다.
23.    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
24.    {
25.        // TODO: 오류 코드를 필요에 따라 수정합니다.
26.        _tprintf(_T("심각한 오류: MFC를 초기화하지 못했습니다.\n"));
27.        nRetCode = 1;
28.    }
29.    else
30.    {
31.        // TODO: 응용 프로그램의 동작은 여기에서 코딩합니다.
32. 
33.        CDatabase db;
34.        db.OpenEx(_T("DSN=OracleTest;UID=scott;PWD=tiger"), 0);
35. 
36.        CRecordset rs(&db);
37.        rs.Open(CRecordset::dynaset, _T("SELECT * FROM EMP"));
38. 
39.        CString str;
40.         
41.        short num = rs.GetODBCFieldCount();
42. 
43.        while(!rs.IsEOF())
44.        {
45.            for(short i = 0; i < num; i++)
46.            {
47.                rs.GetFieldValue(i, str);
48.                if(i == num - 1) wcout << (LPCTSTR)str << endl;
49.                else wcout << (LPCTSTR)str << _T("  ");
50.            }
51.            rs.MoveNext();
52.        }
53.        cout << endl;
54. 
55.        rs.Close();
56.        db.Close();
57.    }
58. 
59.    return nRetCode;
60.}
//