Pro * C/C ++ Windows Programming
Source: Phoenix. Yuwen 2005-11-21
[1] Create a winproc. PC file first
Write the Oracle database-related operations into classes and functions.
Note during pre-Compilation:
You must modify the code, parse, cpp_suffix
1: Select CPP for code
2: Select none or partial for parse.
3: cpp_suffix CPP
[2] generate the winproc. cpp file after successful pre-Compilation
Change this file to the header file winproc. h and import it to your project.
Reference the classes and functions in winproc. h In the Project Development Program to perform database operations.
The following is a winproc. PC file I wrote.
# Include <iostream. h>
# Include <string. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <sqlca. h>
# Include <afxwin. h>
# Include <release a. h>
Exec Oracle option (release_cursor = yes );
Exec SQL include sqlca;
/* SQL variable Declaration */
Exec SQL begin declare section;
Exec SQL end declare section;
Class oracle_proc
{
Public:
Void connect_oracle ();
Void select_ SQL ();
Void SQL _error ();
};
Void oracle_proc: connect_oracle ()
{
/* Log on to the database using user: System/manager */
Exec SQL CONNECT: "Scott" identified by: "Scott ";
/* When Logon fails */
If (sqlca. sqlcode <0)
{
Afxmessagebox (sqlca. sqlerrm. sqlerrmc );
Exec SQL rollback work release;
}
/* When the connection is successful */
Else
{
Afxmessagebox ("/nconnected to Oracle! /N ");
}
};
Void oracle_proc: SQL _error ()
{
Afxmessagebox ("some error... ");
};
Void oracle_proc: select_ SQL ()
{
/* Assign an SQL statement value to an insert statement */
Exec SQL begin declare section;
Char temp [20];
Exec SQL end declare section;
/* Execute SQL */
Exec SQL select dname into: temp from Scott. Dept where deptno = '28 ';
Exec SQL commit work release;
/* Output SQL statement */
Afxmessagebox (temp );
};
Generate winproc. cpp after pre-Compilation
Create an MFC program and import the header file winproc. H to the project. Remember to add the library file orasql8.lib.
Make an experiment in it to see:
Void ctestprocdlg: onbutton1 ()
{
// Todo: add your control notification handler code here
Oracle_proc ora;
Ora. connect_oracle ();
Ora. select_ SQL ();
// Ora. SQL _error ();
}
The result shows that we directly access the Oracle database through MFC + Pro * C/C ++, and the whole process is very simple,
OO ^ ____ ^ oo
Discuss issues together
Email: yuwen05@126.com