Access Oracle Database by Delphi
Xu Changyou
Summary: Delphi has an extremely important role in this field of database programming. This is of course not because of its friendly development interface, but its powerful database engine (BORLAND DATABASE ENGINE, referred to as BDE). This article will detail how to access the Oracle database via Delphi through the specific examples, and the programming of the database.
The main contents include:
Configuring BDE Cognition Oracle ODBC Data Source Add Oracle ODBC Data Source Maintenance Oracle ODBC Data Source Delphi Development Management Oracle Database Example
I. Preparation before the start
Install Oracle 8i (8.0.5) Use a typical installation, installation directory such as f: / oracle; install Delphi 6 Enterprise version, put the Delphi 6 CD into the CD-ROM drive, use typical installation, installation directory is f: / program files / borland / delphi6 Start -> Program -> Oracle for Windows NT-> Oracle Net8 Easy Config Configure Service Name, such as a new service called Yousoft, please refer to Oracle books. Establish an Oracle Data Sheet, Oracle User: Open SQL * Plus, create new users with SYSTEM / Manager users: such as YOUSOFT / YOUSOFT, give resource, connect authority. Built STUDENT Table SQL> Grant Connect, Resource To Yousoft Identified by Yousoft; SQL> CONN YOFT / YOFT is connected. SQL> CREATE TABLE Student (ID Number, Name Char (20), ENGLIST NUMBER (5, 2), Physics Number (5, 2)); Table has been created. SQL> INSERT INTO Student Values (1, 'Xu Changyou', 80, 38); 1 line has been created. SQL> INSERT INTO Student Values (2, 'Li Si', 40, 58); 1 line has been created. SQL> INSERT INTO Student Values (3, 'Zhang 3 ", 89, 98); 1 line has been created. SQL> Insert Into Student Values (4, 'King 5', 68, 78); 1 line has been created. SQL> INSERT INTO Student Values (5, 'Little Sun ", 88, 98); 1 line has been created. SQL> INSERT INTO Student Values (6, 'Horse', 59, 89); 1 line has been created. SQL> Commit; submit completion. SQL> Select * from student; id name englist physics ------------------------------------- -------- 1 Xu Changyou 80 382 Li 4 40 583 Zhang 389 984 Wang 5 68 785 Little Sun 88 986 Horse 59 89 Has selected 6 lines.
Two. Delphi uses BDE to access the Oracle database
Configure BDE Start -> Program -> Borland Delphi 6-> BDE Administrator Configuring Drivers, modify the place where the drawing red circle is modified, respectively, DLL32: SQLORA8.DLL VENDOR init: OCI.dll SqlPassthru Mode: Shared noautocommit modified, click Toolbar Apply or press Ctrl A. After completing the configuration, close the BDE Administrator, then configure Database Aliases, reopen the BDE Administrator to create a new alias, such as set to Useoracle, take the picture: Server Name pull-down Select Yousoft. World, click Apply or press Ctrl A on the toolbar, then double-click Useoracle, enter the connection to enter the username, password (such as: The you build, password), press the "OK" connection. The following indicates successful connection! III. Add and maintain Oracle ODBC data source
ODBC Chinese is an open database link (Open Database Connectivity), is actually a data engine. With the function it provides, you can access the data in the database. It has the advantage that multiple types of data can be handled, such as: DBASE, FoxPro, Paradox, and Oracle. Different databases have their own ODBC drivers. We open the ODBC Data Source Manager from the Control Silver
Switch to the Drives tab, you can see the installed ODBC driver, as shown above.
1. Add ODBC data source
Switch to the System DSN tab, add an Oracle data source, as shown below
Click the Add button to appear as the Create New Data Source dialog shown below.
Select the Microsoft Odbc for Oracle option in the list, click Finish, Enter youoRCE2 in the Data Source Name text box in the Data Source Name text box, enter yousoft and YOUFT.WORLD, click OK to click OK in System DSN The added data source name is seen in the tab.
2. Maintain Oracle ODBC Data Source
Once the ODBC data source is established, it is also possible to make modifications, delete it through the ODBC Data Source Manager. Simply select the data source name, click the Configure button to modify all settings all settings. If you want to delete the selected data source, simply click the Remove button.
IV. Examples of managing Oracle databases using Delphi
Start -> Program -> Borland Delphi 6-> Delphi 6 Start Delphi
Then File-> New-> Application New Application
Add a Database control, a Table control, a DataSource control, and a DBGRID control
Each control property is set as follows:
Name: Oracle_DataBase AliasName select useoracle DatabaseName set oradb LoginPromp set to False Params enter: USER NAME: yousoft PASSWORD: yousoft Connected Set True everything no problem, then you can normally connected to the database Name: Table1 DatabaseName: Select oradb TableName select STUDENT Active Set For ActiveDataSet: Set to Table1 Set the DataSource to DataSource1 to press F9, run this program, the program runs as shown below:
The above is to open the Oracle database using the database access alias, and try again how to use ODBC.
Very simple, just modify the ALIASNAME of the Database control to select the Oracle ODBC Data Source User Acle 2 built in front, the other control properties are the same.
Press F9, run this program, the program runs as shown below:
What is the difference between comparison? Two is the same.
Summary: Through the above learning, you have learned to access and manage the Oracle database through Delphi, but this can only be considered a peak, more waiting for you to learn. If you have anything else, please contact me (my mailbox: Yousoft@chinaren.com Home: http://yousoft.home.chinaren.com) Use Delphi and Oracle, you can completely create powerful projects software. Interested friends can refer to Delphi database programming and Oracle books!