database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
ㆍDB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DB2 Q&A 192 게시물 읽기
No. 192
Re: DB2의 ODBC와 C++에서의 호출법 좀 갈켜주세요
작성자
이전건(leejg68)
작성일
2001-11-21 16:15
조회수
14,052

C++ 이라면 ODBC를 사용하시지 말고 CLI를 이용하시면 됩니다.

 

물론 해당 윈도우 머신에 application development client가 설치되어 있어야 합니다. 그래야 pre-compile을 하실 수 있죠.

 

다음은 sample code입니다.

 

// Source File Name = updat.sqC

//

// Licensed Materials - Property of IBM

//

// (C) COPYRIGHT International Business Machines Corp. 1995, 2000

// All Rights Reserved.

//

// US Government Users Restricted Rights - Use, duplication or

// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

//

//

// PURPOSE: This sample program demonstrates the use of static SQL.

// It updates all managers in the STAFF table of the

// SAMPLE database and changes their job from 'Mgr' to

// 'Clerk', deletes all who are 'Sales', and inserts a

// row. In all three SQL statements (UPDATE, DELETE, INSERT)

// a host variable is implemented.

// Finally, a ROLLBACK is done so that the SAMPLE

// database remains unchanged.

//

// For more information about these samples see the README file.

//

// For more information on programming in C++, see the

// - "Programming in C and C++" section of the Application Development Guide

//

// For more information on building C++ applications, see the:

// - "Building C++ Applications" section of the Application Building Guide.

//

// For more information on the SQL language see the SQL Reference.

//

// For more information about these samples see the README file.

//

// For more information on programming in C++, see the

// - "Programming in C and C++" section of the Application Development Guide

//

// For more information on building C++ applications, see the:

// - "Building C++ Applications" section of the Application Building Guide.

//

// For more information on the SQL language see the SQL Reference.

//

 

#include <iostream.h>

#include <string.h>

#include <stdlib.h>

#include <sqlenv.h>

#include <sqlca.h>

#include "utilemb.h"

 

EXEC SQL INCLUDE SQLCA ;

 

class Update {

public:

Update ();

Update (char *, char *, char *);

int UpdateStaff (char *);

int DeleteStaff (char *);

~Update();

private:

EXEC SQL BEGIN DECLARE SECTION;

char dbname[9];

char userid[9];

char passwd[19];

char jobUpdate[6];

EXEC SQL END DECLARE SECTION;

struct sqlca sqlca;

};

 

Update::Update () {

cout << "Connecting to database SAMPLE... \n";

EXEC SQL CONNECT TO sample;

EMB_SQL_CHECK("CONNECT TO SAMPLE") ;

cout << "Connected to database SAMPLE \n";

}

 

Update::Update (char *dbn, char *user, char *pass) {

strcpy(dbname,dbn);

strcpy(userid,user);

strcpy(passwd,pass);

cout << "Connecting to database " << dbname << "... " << '\n';

EXEC SQL CONNECT TO :dbname USER :userid USING :passwd;

EMB_SQL_CHECK("CONNECT TO SAMPLE");

}

 

int

Update::UpdateStaff(char *jobUD) {

 

strcpy(jobUpdate,jobUD);

EXEC SQL UPDATE staff SET job = :jobUpdate WHERE job = 'Mgr';

EMB_SQL_CHECK("UPDATE STAFF");

cout << "All 'Mgr' have been demoted to '" << jobUpdate << "'!\n";

return 0;

}

 

int

Update::DeleteStaff(char *jobUD) {

 

strcpy(jobUpdate,jobUD);

EXEC SQL DELETE FROM staff WHERE job = :jobUpdate;

EMB_SQL_CHECK("DELETE FROM STAFF") ;

cout << "All '" << jobUpdate << "' people have been deleted!\n";

return 0;

}

 

Update::~Update() {

EXEC SQL ROLLBACK;

EMB_SQL_CHECK("ROLLBACK");

cout << "On second thought ... changes rolled back\n";

 

cout << "Connect resetting from database\n";

EXEC SQL CONNECT RESET;

}

 

 

 

int main (int argc, char *argv[]) {

cout << "Sample C++ program : updat.sqC\n";

 

if (argc == 3) {

Update updateSample ("SAMPLE", argv[1], argv[2]);

 

updateSample.UpdateStaff("Clerk");

updateSample.DeleteStaff("Sales");

} else if (argc == 1) {

Update updateSample;

 

updateSample.UpdateStaff("Clerk");

updateSample.DeleteStaff("Sales");

} else {

cout << "\nUSAGE : updat [userid password]\n\n";

} // end if

 

return 0;

} // end of program : updat.sqC

 

 

-- 이정하 님이 쓰신 글:

>> 윈도우에서 ODBC로 원격의 DB2가 구성이 되어있습니다.

>> C++에서 이 ODBC를 이용하여 connect 하고 insert into 문으로 행을 삽입하고 싶은데요

>> 어째하는지 메뉴얼을 봐도 모르겠습니다.

>> DB프로그래밍에대해 몰라서요

>> 꼭 갈켜주세요

>> 디비 연결하고 인서트 하는 구문의 간략한 예라도 보여주시면

>> 정말로 감사하겠습니다.

>> 꼭요... 수고하세용

[Top]
No.
제목
작성자
작성일
조회
195timestamp타입이나을까요, 그냥 varchar쓰는것이 나을까요?
궁금이
2001-11-22
11128
218┕>Re: timestamp타입이나을까요, 그냥 varchar쓰는것이 나을까요? [1]
이전건
2001-12-02 00:26:39
13334
194블랙박스사용법에 관해서
김희민
2001-11-21
11069
216┕>Re: 블랙박스사용법에 관해서
이전건
2001-12-01 12:13:57
13794
191db2 설치 파일은 어디서 구해야 하나요...
최수정
2001-11-21
11840
193┕>Re: db2 설치 파일은 어디서 구해야 하나요...
이전건
2001-11-21 16:18:38
12011
190DB2의 ODBC와 C++에서의 호출법 좀 갈켜주세요
이정하
2001-11-20
11245
192┕>Re: DB2의 ODBC와 C++에서의 호출법 좀 갈켜주세요
이전건
2001-11-21 16:15:50
14052
179[질문]DB에서 ORACLE의 SQL-PLUS같은 툴
스카이
2001-11-19
11669
187┕>Re: [질문]DB에서 ORACLE의 SQL-PLUS같은 툴
이전건
2001-11-19 16:21:16
12731
178왜 인덱스를 안타죠??
노성섭
2001-11-16
11705
186┕>Re: 왜 인덱스를 안타죠??
이전건
2001-11-19 16:04:58
12793
177[질문] DB2에서 Like 문 사용이 잘 안됩니다.???
정규성
2001-11-15
11770
185┕>Re: [질문] DB2에서 Like 문 사용이 잘 안됩니다.???
이전건
2001-11-19 15:56:23
12739
229┕>Re: [질문] DB2에서 Like 문 사용이 잘 안됩니다.???
정우리
2001-12-10 17:46:42
12779
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.021초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다