Using ASP to implement Oracle database operation _ Application skills

Source: Internet
Author: User
Tags chr error code error handling microsoft sql server ole microsoft frontpage oracle database support microsoft
ASP (Active Server Pages) is one of Microsoft's tools for developing Internet applications, and the ASP's connection to the database is typically done through ADO (Activex Data Object), like the computer World March 20, 2000 As described in the ASP for SQL Server database Operations article, ADO can fully support Microsoft SQL Server, but there are some difficulties with Oracle database services that are more widely used and more complex, and if you want to do some simple query functions, ADO is sufficient if you want to better exploit Oracle database-specific features such as the STORED procedure,stored function, you'll need another powerful tool to access Oracle database services using ASP---Oracle Object The Oracle Object Server in for OLE. This article explains how to use the control provided by Oracle Object Server in ASP to access the Oracle database, and discusses how to maintain the integrity constraint of network database.
----Oracle Object for OLE is a very needed product of Oracle company for client Access databases, which is based on Windows 95/98/NT for all OLE-compatible application and programming languages, such as ASP , Visual Basic excess97 and so on, Oracle object for OLE contains the Oracle Objects server (the Oracle Database Object Server), Orcle Data Control ) with three products such as the Oracle Object class library (the Oracle Objects for OLE C + + class library).
----compared to ADO, Oracle Object servers are products dedicated to the development of Oracle database applications, which have the following advantages:
----(1) The connection to the database server is running efficiently. Because ADO is connected to the database server through ODBC, the Oracle Object Server connects to the database server through Oracle Sql*net
----(2) can better play the unique functions of Oracle database. such as STORED procedure,stored FUNCTION, package, or multiple Cursor.
----This example is a directory of inquiries, entry of the small program, users can use the browser to query the address list, you can also input their own information for others to query.
The structure of the----Address Book table is as follows:
Name Null? Type
------------------------------- -------- ----
NAME not NULL CHAR (8)
Address CHAR (20)
PHONE CHAR (20)
EMAIL VARCHAR2 (30)
----First: Configure the Environment:
----Install the following software on the Web server and configure it:
----(1) Basic Web server (Web server) and ASP software
----(2) Oracle Object for ole2.x
----(3) sql*net client or Oracle NET8 client 8, after installation, use Sql*net Easy configuration to establish the database alias, the alias used to connect the ASP to the database.
----two. function realization
----(1) query: Use ASP to take the database Address Book list (TSB1) data, display the data on the screen. The key of the query is to determine whether the connection to the database is successful, the Oracle Object Server itself has error control mechanism to report the errors of the database connection, the specific procedures are as follows:
< HTML >
< tile > Query program </title >
< BODY >
<%
On Error Resume Next
' Connect to the database
Set Orasession=createobject
("Oracleinprocserver.xorasession")
Set Oradatabase=orasession.
Dbopendatabase ("axp03", "Scott/tiger", 0)
' Error handling
If Err.Number >0 Then
Response.Write "< h4 >asp error control </H4 >"
Response.Write "ASP Error Source:" &err.source & "< br >"
Response.Write "ASP Error code:" &err.number& "< br >"
Response.Write "ASP Error Description:" &err.description& "< br >"
Err.Clear
Response.Write "< h4 >oracle OLE error control </H4 >"
Response.Write ORACLE Error Code:
"&OraSession.LastServerErr&" < br > "
Response.Write ORACLE Error Description:
"&OraSession.LastServerErrText&" < br > "
Else
' Query
Sql= "SELECT * from TSB1"
Set Oradynaset=oradatabase.dbcreatedynaset (sql,0)
Response.Write "< h3 >result

Response.Write "< table border=5 >< tr >"
For I=0 to Oradynaset.fields.count-1
Response.Write "< td >"
Response.Write Oradynaset.fields (i). Name & ""
Response.Write "</td >"
Next
Response.Write "</tr >"
Do Until oradynaset.eof
Response.Write "< tr >"
For I=0 to Oradynaset.fields.count-1
Response.Write "< td >"
Response.Write Oradynaset.fields (i). Value
Response.Write "</td >"
Next
Response.Write "</tr >"
Oradynaset.dbmovenext
Loop
Response.Write "</table >"
' Close the database
Oradatabase.close
Set orasession=nothing
End If
% >
</body >
----The following is the program's query result surface:
Contacts
NAME Address PHONE EMAIL
Zhangling Maanshan, No. 5th Hubei Road, 0555-2887765 zhangl@mial.magang.com.cn
Lin to Maanshan Hunanlu No. 9th 0555-2223856 lingx@mail.magang.com.cn
Deng Mining Road 4 Building No. 504 0555-2474748 denggh@263.net
Li Cheng Qingdao Ocean University 7 507 0464-32456678 Licheng@263.net
Kingdom in the mining Community 7 building No. 807 0555-3445454 wang@mail.amgang.com.cn
0555-2883721 dingg@mail.magang.com.cn, No. 17, Dinggang Hongqi Rd., South China
0554-4566777 quzab@mial.ccac.com, no. No. 607, 7 Building, Jiangxi Road, Bao ' an
----(2) Insert their own information: Using ASP to the user in the browser provided by inserting data into the database address list (TSB1), the Oracle database has a set of integrity constraints, so the insertion process is not simply to insert data into the table, but also to do integrity constraints of the check, Undesirable data rejection is inserted, if the process is not considered in the program, run, will be interrupted by the database server error program. The Err object in ASP can report the source of error, error code, error description, etc., and can lead the program to error handling.
----The following is the program, one is insert.htm, is an input interface for users to enter their own information, one is insert.asp, responsible for the user input information into the database, and error checking.
Insert.htm:
< HTML >
< head >
< meta http-equiv= "Content-language"
Content= "ZH-CN" >
< meta http-equiv= "Content-type"
Content= "text/html; charset=gb2312 ">
< meta name= "generator" content=
"Microsoft FrontPage 4.0" >
< meta name= "ProgId" content=
"FrontPage.Editor.Document" >
< title > Please leave your message </title >
< BODY >
< p align= "center" > Please enter your information </p >
< form method= "POST" action= "insert.asp" >
Name
< input type= "text" name= "name" size= "8" > < br >
Address
< input type= "text" name= "address" size= "> < br >
Phone
< input type= "text" name= "Phone" size= "> < br >
e-mail:< input type= "text" name= "email" size= "> < br >
< input type= "submit" value= "OK" >
< input type= "reset" value= "Cancel" >< br >
</form >
</body >
----Below is the user input interface:
Please enter your information
Name
Address
Phone
E-Mail:
Insert.asp:
< HTML >
< BODY >
<%
' Connect to the database
Set Orasession=createobject
("Oracleinprocserver.xorasession")
Set Oradatabase=orasession.
Dbopendatabase ("axp03", "Scott/tiger", 0)
' Insert user information into SQL statement
Sql= "INSERT into TSB1 values
("&AMP;CHR" &request ("name") &AMP;CHR & "," _
&AMP;CHR (&request) &AMP;CHR ("Address") & "," _
&AMP;CHR & Request ("Phone") &AMP;CHR & "," _
&AMP;CHR (&request) ("EMAIL") &AMP;CHR & ")"
' Run SQL INSERT statement
Oradatabase.dbexecutesql (SQL)
' Check for violations of integrity constraint errors
IF ERR. Number >0 THEN
Response.Write "< h4 >asp error control </H4 >"
Response.Write "ASP Error Source:" &err.source & "< br >"
Response.Write "ASP Error code:" &err.number& "< br >"
Response.Write "ASP Error Description:" &err.description& "< br >"
ELSE
' Insert complete, return
Response.Write "Insert Complete,< a href=insert.htm > Return ... < a > "
End If
% >
</body >
----above is I use ASP tools to the original Oracle database information to the Internet application of some experience, the example is very simple, the purpose is to explain the principle, I in the ASP program also used STORED procedure,stored FUNCTION, PACKAGE Oracle-specific functions to speed up and improve efficiency. Hope to be able to enlighten you, please send a letter to communicate with each other.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.