Re: C und DB2Geschrieben von Bunbury on November 21, 2002 um 20:20: Als Antwort auf C und DB2 geschrieben von Sven Schneider on November 21, 2002 um 13:25: Hi Sven, mit Hilfe von Embedded SQL kann man von C aus auf DB2-Tabellen zugreifen (SELECT, UPDATE, DELETE, INSERT, etc). Falls das Anwendungsprogramm auf einer anderen Hardwareplattform läuft als die Datenbank selbst, benötigst Du noch eine passende Middleware, wie z. B. DB2 Connect, die die Verbindung herstellt. Nachfolgend noch ein kleines Beispielprogrämmchen in C mit SQL. Viel Glück
#include /* sqlca: is the sql communications area. All error codes ************************************* EXEC SQL INCLUDE SQLCA; /* SQL communication area structure */ EXEC SQL BEGIN DECLARE SECTION; /* declare host variables */ void main() { strcpy(db_name, "csc2509h"); /* C variables are preceded by a colon when they are passed to DB2 */ EXEC SQL CONNECT TO :db_name; if (sqlca.sqlcode != 0) { /* cursor declaration. Have to declare a cursor each time you EXEC SQL DECLARE c1 CURSOR FOR /* you have to open the cursor in order to get tuples back */ EXEC SQL OPEN c1; do { /* fetch tuples from the cursor. This will execute the statement EXEC SQL FETCH c1 into :video_title; /* host variables should have ':' prefix when they are used in DB2 commands */ printf("%s\n",video_title); } while (1);
Antworten:
|