Document directory
- I. Preparations before the start
- 2. Delphi uses BDE to access the Oracle database
- 3. Add and maintain Oracle ODBC Data sources
- 4. Use Delphi to develop and manage Oracle database instances
Use Delphi to access the Oracle database Xu Changyou
Summary: Delphi plays an extremely important role in the field of database program design. This is certainly not because of its friendly development interface, but its powerful Database Engine (Borland Database Engine, BDE ). This article describes in detail how to access the Oracle database through Delphi and how to design the database program.
The main content includes:
- Configure BDE
- Understanding Oracle ODBC Data sources
- Add an Oracle ODBC Data Source
- Maintain Oracle ODBC Data sources
- Example of developing and managing Oracle databases using Delphi
I. Preparations before the start
- Install Oracle 8i (8.0.5) using a typical installation directory, such as F:/Oracle;
- Install Delphi 6 Enterprise Edition and put the Delphi 6 CD-Rom into the optical drive. The typical installation directory is F:/Program Files/Borland/Delphi6;
- Start-> Program-> Oracle for Windows NT-> Oracle Net8 Easy Config configure the Service Name, for example, add a Service named YOUSOFT. for more information, see Oracle books.
- Create an Oracle data table. Oracle users:
Open SQL * Plus and Log On As A system/manager User.
Create a new user, such as yousoft/yousoft, and grant the resource and connect permissions. Create a student table
SQL> grant connect, resource to yousoft identified by yousoft;
SQL> conn yousoft/yousoft
Connected.
SQL> create table student (ID number, name char (20), Englist number (5, 2), physics number (5, 2 ));
The table has been created.
SQL> insert into student values (1, 'xu Changyou ', 80, 38 );
One row has been created.
SQL> insert into student values (2, 'lily );
One row has been created.
SQL> insert into student values (3, 'zhang san', 89,98 );
One row has been created.
SQL> insert into student values (4, 'wang wu', 68, 78 );
One row has been created.
SQL> insert into student values (5, 'grandchildren, 88,98 );
One row has been created.
SQL> insert into student values (6, 'marat );
One row has been created.
SQL> commit;
Submitted.
SQL> select * from student;
ID NAME ENGLIST PHYSICS
-----------------------------------------------
1 Xu Changyou 80 38
2 Li Si 40 58
3 Zhang San 89 98
4 Wang Wu 68 78
5 sun 88 98
6 Ma 59 89
You have selected 6 rows.
2. Delphi uses BDE to access the Oracle database
- Configure BDE
Start> program> Borland Delphi 6> BDE Administrator
- Configure Drivers and modify the red circle.
Dll32: sqlora8.dll
Vendor init: OCI. dll
Sqlpassthru mode: Shared noautocommit
After the modification, click Apply on the toolbar or press Ctrl + A. After the configuration is complete, disable BDE administrator. then configure database aliases (Database Access alias) and re-open BDE administrator to create an alias, for example, set useoracle:
Select yousoft. World from the server name drop-down list, click Apply on the toolbar or press Ctrl + A, and double-click useoracle to enter the connection.
Enter the user name and password (for example, the yousoft password created above), and press OK to connect. The following shows that the connection is successful!
3. Add and maintain Oracle ODBC Data sources
ODBC Chinese is Open DataBase Connectivity, which is actually a Data Engine. It provides functions to access data in the database. It can process various types of data, such as dBase, FoxPro, Paradox, and Oracle. Different databases have their own ODBC drivers. Open the ODBC data source Manager from the Control Panel
Switch to the drivers tab to view the installed ODBC driver, as shown in.
1. Add an ODBC Data Source
Switch to the System DSN tab and add the Oracle Data Source here, as shown in
Click Add to display the Create New Data Source dialog box, as shown in.
Select the Microsoft ODBC for Oracle option in the list and click Finish to identify the Data Source. In the Data Source Name text box, enter useoralce2, User Name, and Server, respectively, and enter yousoft and yousoft. world, click OK to view the name of the added data source on the System DSN tab.
2. Maintain the Oracle ODBC Data Source
Once an ODBC data source is created, you can use the ODBC data source Manager to conveniently modify and delete it. You only need to select the data source name and click the Configure button to modify all settings of the data source. To delete a selected data source, click the Remove button.
4. Use Delphi to develop and manage Oracle database instances
Start-> Program-> Borland Delphi 6-> Delphi 6 start Delphi
Then File-> New-> Application creates an Application.
Add a DataBase Control, a Table control, a DataSource control, and a DBGrid control.
The property settings of each control are as follows:
|
Name: oracle_database Aliasname: useoracle Set databasename to oradb Set loginpromp to false Input in Params: User name: yousoft password: yousoft Set connected to true If everything is okay, you can connect to the database normally. |
|
Name: Table1 DatabaseName: Select oradb TableName select STUDENT Set Active to Active |
|
Dataset: Set to Table1 |
|
Set datasource to performance1. |
Press F9 to run the program. The program runs as follows:
The preceding example shows how to use the database access alias to open the Oracle database.
You only need to modify the AliasName of the database Control and select the Oracle ODBC Data Source useoracle2 we created earlier. The attributes of other controls remain the same as above.
Press F9 to run the program. The program runs as follows:
What are the differences between them? The two are the same.
Summary: Through the above study, you have learned to access and manage the Oracle database through Delphi, but this is only a glimpse of the leopard, and more are waiting for you to learn. If there is anything you don't understand above, please contact me (my mailbox: yousoft@chinaren.com homepage: http://yousoft.home.chinaren.com) with Delphi and Oracle, you can create powerful engineering software. If you are interested, please refer to the Delphi Database Programming and Oracle books!