Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle and NT text-mode progs.
In article <E0I4u3.MqC_at_falcon.daytonoh.ncr.com> Brian.Sakach_at_daytonoh.ncr.com (Brian Sakach) writes:
>From: Brian.Sakach_at_daytonoh.ncr.com (Brian Sakach)
>Subject: Re: Oracle and NT text-mode progs.
>Date: Thu, 7 Nov 1996 13:15:39 GMT
>How about sharing a small example with us? Thanks.
Here's a stripped down, medium-case sample using ODBC. (PRO*C would be simpler, OCI would be more difficult.) This builds as an NT/Win95 console mode program, and is not Oracle-specific:
#include <windows.h> #include <stdio.h> #include <sqlext.h>
int main (int argc, char *argv[])
{
int nResult; char szQuery[256]; char szBuffer[256]; char szColumn1[256]; char szColumn2[256]; SDWORD sdwBufferLen; char szDataSource[] = "Oracle"; char szUserID[] = "scott"; char szPassword[] = "tiger"; // Allocate ODBC Environment Handle nResult = SQLAllocEnv(&ghOracleEnv); if (nResult) return (-1); // Allocate ODBC Connection Handle nResult = SQLAllocConnect(ghOracleEnv, &ghOracleDbc); if (nResult) return (-1); // Connect to database nResult = SQLConnect(ghOracleDbc, szDataSource, (SWORD) strlen(szDataSource), szUserID, (SWORD) strlen(szUserID), szPassword, (SWORD) strlen(szPassword); if (nResult) return (-1); // Allocate ODBC Statement Handle nResult = SQLAllocStmt(ghOracleDbc, &ghOracleStmt); if (nResult) return (-1); // Execute some simple select statement strcpy (szQuery, "select col_1, col_2 from some_table"); nResult = SQLExecDirect(ghOracleStmt, szQuery, strlen(szQuery)); if (nResult) return (-1); // Loop through all the rows returned while (SQLFetch (ghOracleStmt) != SQL_NO_DATA_FOUND) { // Retrieve First Column SQLGetData(ghOracleStmt, 1, SQL_C_CHAR, szBuffer, 256, &sdwBufferLen); strcpy (szColumn1, szBuffer); // Retrieve Second Column SQLGetData(ghOracleStmt, 2, SQL_C_CHAR, szBuffer, 256, &sdwBufferLen); strcpy (szColumn2, szBuffer); // Print the row data printf ("Column 1 = %s, Column 2 = %s\n", szColumn1, szColumn2); } // Clean up and exit SQLFreeStmt(ghOracleStmt, SQL_DROP); SQLDisconnect(ghOracleDbc); SQLFreeConnect(ghOracleDbc); SQLFreeEnv(ghOracleEnv); return (0);