1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Practical Database Programming With Visual C#.NET- P18 pptx

31 591 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Build ASP.NET Web Service to Update and Delete Data for Oracle Database
Trường học University of Science and Technology of Hanoi
Chuyên ngành Computer Science
Thể loại tutorial
Thành phố Hanoi
Định dạng
Số trang 31
Dung lượng 771,04 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The point is that the data type of each input parameter must be identical with the data type of each data column used in the Course table.. The fi rst query is used to get the faculty_id

Trang 1

9.12.1 Build Web Service Project

Web S ervice O racle U pdate D elete

In this section, we will modify an existing Web Service project WebServiceSQLUpdateDelete

to make it our new Web Service project WebServiceOracleUpdateDelete, and enable it

to update and delete data in our sample Oracle database

Open Windows Explorer and create a new folder Chapter 9 under the root directory

if you have not done that Open Internet Explorer and browse to our desired Web Service project WebServiceSQLUpdateDelete at the folder DBProjects\Chapter 9 located at the accompanying ftp site (see Chapter 1 ) Copy and paste this project into our new folder Chapter 9 Rename it WebServiceOracleUpdateDelete Perform the following modifi ca- tions to this project in the Windows Explorer window:

1 Change the main Web Service page from WebServiceSQLUpdateDelete.asmx to WebServiceOracleUpdateDelete.asmx

2 Open the App_Code folder and change the name of our base class fi le from SQLBase.cs

• Change CodeBehind= " ~ /App_Code/WebServiceSQLUpdateDelete.cs " to

• Change the class name and the constructor ’ s name from SQLBase to OracleBase

• Change the name of the fi rst member data from SQLOK to OracleOK

• Change the name of the second member data from SQLError to OracleError

Go to the File|Save All menu item to save these modifi cations

9.12.2 Modify Connection String

Double - click on our Web confi guration fi le web.config from the Solution Explorer window to open it Change the content of the connection string that is under the tag

< connectionStrings > to:

< add name= " ora_conn " connectionString= " Server=XE;

User ID=CSE_DEPT;Password=reback; " >

Trang 2

The Oracle database server XE is used for the server name, the user ID is the name

of our sample database CSE_DEPT , and the password is determined by the user when adding a new account to create a new user database

First, we need to add an Oracle Data Provider Reference to our Web Service project

To do that, right - click on our new project icon WebServiceOracleUpdateDelete from the Solution Explorer window, and then select the item Add Reference from the pop - up menu to open the Add Reference dialog box Browse down along the list until you fi nd the item System.Data.OracleClient , click to select it and then click on the OK button

to add it into our project

Now double - click on our code - behind page WebServiceOracleUpdateDelete.cs to open it On the opened page, add the Oracle namespace to the namespace area on this page.

using System.Data.OracleClient;

Also change the name of our Web Service class, which is located after the accessing mode public class , from WebServiceSQLUpdateDelete to WebServiceOracle UpdateDelete Perform the same modifi cation to the constructor ’ s name of this class

Next we will perform the necessary modifi cations to four Web methods developed

in this Web Service project combined with those fi ve differences listed above

The following issues are related to this modifi cation:

1 The name of this Web method and the name of the returned data type class

2 The content of the query string used in this Web method

3 The stored procedure used in this Web method

4 The names of the data components used in this Web method

5 The user - defi ned SQLConn() and ReportError() methods

6 The names of the dynamic parameters

Let ’ s perform those modifi cations step by step according to this sequence Open the Web method SQLUpdateSP() and perform the modifi cations shown in Figure 9.138 to this method

Let ’ s take a closer look at these modifi cations to see how they work

A Rename this Web method OracleUpdateSP and change the name of the returned class

to OracleBase

B Modify the content of the query string by changing the name of the stored procedure from

dbo.WebUpdateCourseSP to UpdateCourse_SP The former is an SQL Server stored procedure and the latter is an Oracle stored procedure that will be developed in the next section

Trang 3

C Change the prefi x from Sql to Oracle for all data classes and from sql to ora for all data objects Also change the returned instance name from SQLResult to OracleResult

D Change the name of the returned instance from SQLResult to OracleResult and member

data from SQLOK to OracleOK

E Change the name of the subroutine from SQLConn to OracleConn

F Change the prefi x from sql to ora for all data objects

//Uncomment the following line if using designed components //InitializeComponent();

} [WebMethod]

publicOracleBaseOracleUpdateSP(string FacultyName, string CourseID, string Course, string Schedule,

string Classroom, int Credit, int Enroll) {

string cmdString = "UpdateCourse_SP";

OracleConnectionoraConnection = new OracleConnection();

OracleBaseOracleResult = new OracleBase();

OracleCommandoraCommand = new OracleCommand();

int intUpdate = 0;

OracleResult.OracleOK = true;

oraConnection = OracleConn();

if (oraConnection == null) {

OracleResult.OracleError = "Database connection is failed";

oraCommand.Parameters.Add("FacultyName", OracleType.VarChar).Value = FacultyName;

oraCommand.Parameters.Add("inCourseID", OracleType.Char).Value = CourseID;

oraCommand.Parameters.Add("inCourse", OracleType.VarChar).Value = Course;

oraCommand.Parameters.Add("inSchedule", OracleType.Char).Value = Schedule;

oraCommand.Parameters.Add("inClassroom", OracleType.VarChar).Value = Classroom;

oraCommand.Parameters.Add("inCredit", OracleType.Int32).Value = Credit;

oraCommand.Parameters.Add("inEnroll", OracleType.Int32).Value = Enroll;

intUpdate = oraCommand.ExecuteNonQuery();

oraConnection.Close();

oraCommand.Dispose();

if (intUpdate == 0) {

OracleResult.OracleError = "Data updating is failed";

ReportError(OracleResult);

} returnOracleResult;

}

A

B C

D E F

Trang 4

G Modify the nominal names for all seven input parameters to the stored procedure by

removing the @ symbol before each nominal name Also change the data type of the top

fi ve input parameters from SqlDbType.Text to OracleType.VarChar Change the data type for the last two input parameters from SqlDbType.Int to OracleType.Int32 The

prefi x in for the last six parameters matchs the input parameters used for the stored

pro-cedure UpdateCourse_SP()

H Change the prefi x from sql to ora for all data objects

I Change the name of the returned instance from SQLResult to OracleResult and change

the second member data from SQLError to OracleError

Your modifi ed Web method OracleUpdateSP() is shown in Figure 9.138 All modifi ed parts have been highlighted in bold

Next let ’ s perform modifi cations to two related user - defi ned methods SQLConn() and ReportError()

Perform the following modifi cations to the SQLConn() method:

A Change the name of this method from SQLConn to OracleConn and return class name

from SqlConnection to OracleConnection Also change the connection string from sql_

conn to ora_conn

B Change the data type of the returned connection object to OracleConnection

Perform the following modifi cations to the ReportError() method:

C Change the data type of the passed argument from SQLBase to OracleBase

D Change the name of the fi rst member data from SQLOK to OracleOK

E Change the name of the second member data from SQLError to OracleError

Your modifi ed methods OracleConn() and ReportError() should match that shown

in Figure 9.139 All modifi ed parts have been highlighted in bold

Next let ’ s develop the stored procedure UpdateCourseSP to perform the course updating function

protected OracleConnection OracleConn()

{ string cmdString = ConfigurationManager.ConnectionStrings["ora_conn"].ConnectionString;

OracleConnection conn = new OracleConnection();

conn.ConnectionString = cmdString;

conn.Open();

if (conn.State != System.Data.ConnectionState.Open) {

MessageBox.Show("Database Open is failed");

conn = null;

} return conn;

} protected void ReportError(OracleBase ErrSource) {

Figure 9.139 Modifi ed methods OracleConn and ReportError

Trang 5

9.12.4.1 Develop Stored Procedure Update C ourse_ SP

A very detailed discussion of creating and manipulating packages and stored procedures

in Oracle database is provided in Section 5.20.3.5 in Chapter 5 Refer to that section to get more detailed information for creating Oracle ’ s stored procedures

The topic we discuss in this section is to update and delete data in the database

Therefore no returned data is needed for these two data actions We only need to create stored procedures in Oracle database, not packages, to perform the data updating and deleting function

As discussed in Section 5.20.3.6 in Chapter 5 , different methods can be used to create Oracle ’ s stored procedures In this section, we will use the Object Browser page provided

by Oracle Database 10g XE to create our stored procedures

Open the Oracle Database 10g XE home page by going to Start|All Programs|Oracle Database 10g Express Edition|Go To Database Home Page items Finish the login process by entering the correct username and password such as CSE_DEPT and reback Click on the Object Browser and select Create|Procedures item to open the Create Procedure window Click on the Create button and select the Procedure icon from the list to open this window

Enter UpdateCourse_SP into the Procedure Name box and keep the Include Argument checkbox checked, and click on the Next button to go to the next page

The next window is used to allow us to enter all input parameters For this stored procedure we need to perform two queries Therefore we have seven input parameters The fi rst query is to get the faculty_id from the Faculty table based

on the faculty name that is an input and selected by the user The second query

is to update a course record that contains six pieces of information related to a current course in the Course table based on the faculty_id that is obtained from the fi rst query The seven input parameters are FacultyName, CourseID, CourseTitle, Credit, Classroom, Schedule, and Enrollment The fi rst input parameter FacultyName

is used by the fi rst query, and the following six input parameters are used by the second query

Enter those input parameters one by one into the argument box The point is that the data type of each input parameter must be identical with the data type of each data column used in the Course table Refer to Section 2.11.2.3 in Chapter 2 to get a detailed list of data types used for those data columns in the Course data table

For the Input/Output parameter defi nitions, select IN for all seven parameters since

no output is needed for this data updating query Your fi nished argument list should match that shown in Figure 9.140

Click on the Next button to go to the procedure defi ning page Enter the codes shown

in Figure 9.141 into this new procedure as the body of the procedure using the language

of so - called Procedural Language Extension for SQL or PL - SQL Then click on the Next and on the Finish buttons to confi rm creating this procedure Your fi nished stored pro- cedure should match that shown in Figure 9.142

Seven input parameters are listed at the beginning of this procedure with the keyword

IN to indicate that these parameters are inputs to the procedure The intermediate parameter faculty_id is obtained from the fi rst query from the Faculty table The data

type of each parameter is indicated after the keyword IN , and it must be identical with the data type of the associated data column in the Course table An IS command is

Trang 6

attached after the procedure header to indicate that an intermediate query result,

faculty_id , will be held by a local variable facultyID declared later

Two queries are included in this procedure The fi rst query is used to get the

faculty_id from the Faculty table based on the input parameter FacultyName , and the second query is to update a course record based on six input parameters in the Course table A semicolon must be attached after each PL - SQL statement

One important issue is that you need to create one local variable FacultyID and

attach it after the IS command as shown in line 9 in Figure 9.142 , and this coding line has

been highlighted with shading Click on the Edit button to add this local variable with its data type of VARCHAR2(10) This local variable is used to hold the returned faculty_

id from the execution of the fi rst query

Another important issue in arranging the input parameters or arguments in the UPDATE command is that the order of those parameters or arguments must be identical with the order of the columns in the associated data table For example, in the Course table, the order of the data columns is course_id, course, credit, classroom, schedule, enrollment , and faculty_id Accordingly, the order of input parameters

Figure 9.140 Finished argument list

SELECT faculty_id INTO FacultyID FROM Faculty WHERE faculty_name = FacultyName;

UPDATE Course SET course=inCourse, credit=inCredit, classroom=inClassroom, schedule=inSchedule, enrollment=inEnroll, faculty_id=FacultyID

WHERE course_id=inCourseID;

Figure 9.141 Stored procedure body

Trang 7

Figure 9.142 Completed stored procedure

placed in the UPDATE argument list must be identical with the data columns ’ order displayed above

To make sure that this procedure works properly, we need to compile it fi rst Click

on the Compile button to compile and check our procedure A successful compilation message should be displayed if our procedure is a bug - free stored procedure Close the Oracle Database 10g Express Edition by clicking the Close button

9.12.5 Modify Web Method Get SQLC ourse

and Related Methods

The function of this Web method is to retrieve all course_id, which includes the original and the new inserted course_id , from the Course table based on the input faculty name This Web method will be called or consumed by a client project later to get back and display all course_id in a listbox control in the client project

Recall that in Section 5.19.2.5 in Chapter 5 , we developed a joined - table query to perform the data query from the Course table to get all course_id based on the faculty name The reason for that is because there is no faculty name column available in the Course table, and each course or course_id is related to a faculty_id in the Course table In order to get the faculty_id that is associated with the selected faculty name, one must fi rst go to the Faculty table to perform a query to obtain it In this situation, a join query is a desired method to complete this function

Open this Web method and perform the following modifi cations that are shown in Figure 9.143 to this method All modifi ed parts have been highlighted in bold

Trang 8

Let ’ s take a closer look at these modifi cations to see how they work

A Change the name of this Web method from GetSQLCourse to GetOracleCourse Also

change the name of the returned instance from SQLBase to OracleBase

B Modify the query string to match it to the ANSI 89 standard Recall that we developed a

join - table query string for SQL Server database using the ANSI 92 standard in Section 5.19.2.5 in Chapter 5 Since the ANSI 89 standard is still being used in the Oracle database,

we need to modify this joined - table query string by using that standard

C Change the prefi x of all data classes from Sql to Oracle and from sql to ora for all data objects used in this method Also change the name of the returned instance from SQLResult

to OracleResult Change the fi rst member data from SQLOK to OracleOK

D Change the name of the user - defi ned method from SQLConn to OracleConn Change the

second member data from SQLError to OracleError

E Change the prefi x of all data objects from sql to ora Change the second member data from SQLError to OracleError

F Modify the nominal name for the input parameter to the stored procedure by removing

the @ symbol before the nominal name fname Also change the data type of this input parameter from SqlDbType.Text to OracleType.VarChar

[ WebMethod ] publicOracleBase GetOracleCourse(string FacultyName) {

string cmdString = "SELECT Course.course_id FROM Course, Faculty " + "WHERE (Course.faculty_id = Faculty.faculty_id) AND (Faculty.faculty_name =: fname)";

OracleConnectionoraConnection = newOracleConnection ();

OracleBaseOracleResult = newOracleBase ();

OracleCommandoraCommand = newOracleCommand ();

OracleDataReaderoraReader;

OracleResult.OracleOK = true ;

oraConnection = OracleConn();

if (oraConnection == null ) {

OracleResult.OracleError = "Database connection is failed";

ReportError(OracleResult);

return null ; }

else {

OracleResult.OracleError = "No matched course found";

D E

F

G

H WebServiceOracleUpdateDelete GetOracleCourse()

Figure 9.143 Modifi ed Web method GetOracleCourse

Trang 9

G Change the names of two passed arguments to the method FillCourseReader() from SQLResult to OracleResult and from sqlReader to oraReader

H Change the name of the returned instance from SQLResult to OracleResult , change the

second member data from SQLError to OracleError , and change the prefi x for all data objects from sql to ora

The modifi cations to the related user - defi ned FillCourseReader() method are tively simple Perform the following modifi cations to this method:

A Modify the data types of two passed arguments by changing the data type of the fi rst

argu-ment from SQLBase to OracleBase and changing the data type of the second arguargu-ment from SqlDataReader to OracleDataReader

B Change the method from GetSQLString(0) to GetOracleString(0)

Your modifi ed user - defi ned FillCourseReader() method should match that shown in Figure 9.144 All modifi ed parts have been highlighted in bold Next let ’ s modify another Web method GetSQLCourseDetail()

9.12.6 Modify Web Method Get SQLC ourse D etail and

Related Methods

The function of this Web method is to retrieve the detailed information for a selected

course_id that works as an input parameter to this method, and store the retrieved information to an instance that will be returned to the calling procedure

The following three modifi cations need to be performed for this Web method:

1 Modify the codes of this Web method

2 Modify the related user - defi ned FillCourseDetail() method

3 Modify the content of the query string and make it equal to the name of an Oracle Package

WebSelectCourseSP we developed in Section 9.10.7

Open this Web method and perform the modifi cations shown in Figure 9.145 to this Web method

Let ’ s take a closer look at these modifi cations to see how they work

A Change the name of this Web method from GetSQLCourseDetail to GetOracleCourseDetail Also change the name of the returned base class from SQLBase

sResult.CourseID[pos] = Convert.ToString(sReader.GetOracleString(0)); //the 1st column is course_id pos++;

} }

Trang 10

B Modify the content of the query string and make it equal to the name of the Package we

developed in the Section 9.10.7 Change this query string from dbo.WebSelectCourseSP

to WebSelectCourseSP.SelectCourse The prefi x WebSelectCourseSP is a Package and the SelectCourse is a stored procedure

C Change the prefi x of all data classes from Sql to Oracle and from sql to ora for all data objects used in this method Also change the name of the returned instance from SQLResult

to OracleResult Change the fi rst member data from SQLOK to OracleOK

D Add two OracleParameter objects paramCourseID and paramCourseInfo Because some

differences exist between the SQL Server and Oracle databases, we need to use different ways to assign parameters to the Parameters collection of the Command object later

E Change the name of the user - defi ned method from SQLConn to OracleConn Change the

second member data from SQLError to OracleError

[ WebMethod ] publicOracleBase GetOracleCourseDetail(string CourseID) {

string cmdString = "WebSelectCourseSP.SelectCourse";

OracleConnectionoraConnection = newOracleConnection ();

OracleBaseOracleResult = newOracleBase ();

OracleDataReaderoraReader;

OracleParameter paramCourseID = new OracleParameter ();

OracleParameter paramCourseInfo = new OracleParameter ();

OracleResult.OracleOK = true ;

oraConnection = OracleConn();

if (oraConnection == null ) {

OracleResult.OracleError = "Database connection is failed";

ReportError(OracleResult);

return null ; }

paramCourseID.ParameterName = "CourseID";

paramCourseID.OracleType = OracleType VarChar;

paramCourseID.Value = CourseID;

paramCourseInfo.ParameterName = "CourseInfo";

paramCourseInfo.OracleType = OracleType Cursor;

paramCourseInfo.Direction = ParameterDirection Output; //this is very important OracleCommandoraCommand = newOracleCommand(cmdString, oraConnection);

oraCommand.CommandType = CommandType StoredProcedure;

oraCommand.Parameters.Add(paramCourseID);

oraCommand.Parameters.Add(paramCourseInfo);

oraReader = oraCommand.ExecuteReader();

if (oraReader.HasRows == true ) FillCourseDetail( refOracleResult, oraReader);

else {

OracleResult.OracleError = "No matched course found";

Trang 11

F Initialize two OracleParameter objects by assigning them with the appropriate values The

point is, for the second parameter paramCourseInfo , the data type of this parameter is

Cursor and the Direction is Output Both values are very important to this parameter and must be assigned exactly as we did here Otherwise a running exception will be encoun-tered when the project runs

G Add two statements to add two OracleParameter objects to the Command object

H Change the names of two passed arguments to the FillCourseDetail() method from SQLResult to OracleResult and from sqlReader to oraReader

I Change the name of the returned instance from SQLResult to OracleResult and change

the second member data from SQLError to OracleError

The modifi cations to the related user - defi ned FillCourseDetail() method are simple

The only modifi cations are to change the data type of two passed arguments sResult and sReader Change the data type of the fi rst argument from SQLBase to OracleBase , and change the data type for the second argument from SqlDataReader to OracleDataReader

9.12.7 Modify Web Method SQLD elete SP

As we discussed in Section 7.1.1 in Chapter 7 , to delete a record from a relational base, one needs to follow the operation steps listed below:

1 Delete records that are related to the parent table using the foreign keys from child tables

2 Delete records that are defi ned as primary keys from the parent table

In other words, to delete one record from the parent table, all records that are related

to that record as foreign keys and located at different child tables must be deleted fi rst

In our case, in order to delete a record using the course_id as the primary key from the Course table (parent table), one must fi rst delete those records using the course_id

as a foreign key from the StudentCourse table (child table) Fortunately we have only one child table related to our parent table in our sample database Refer to Section 2.5 and Figure 2.5 in Chapter 2 to get a clear relationship description among different data tables in our sample database

From this discussion, it can be found that to delete a course record from our sample database two deleting queries should be performed: The fi rst query is used to delete the related records from the child table or the StudentCourse table, and the second query is used to delete the target record from the parent table or the Course table Of course, we can place these two queries into a stored procedure WebDeleteCourseSP(), which we will develop in the following section to perform this deleting action However, recall that

in Section 2.11.3.5 in Chapter 2 , we set a one - to - many constraint relationship between the Course and the StudentCourse tables with an On Delete Cascade mode (refer to Figure 2.65 ) This mode means that all records with a course_id that is equal to a

deleted if that course_id is deleted from the Course (parent) table With this On Delete Cascade mode, we can use a single statement in this stored procedure to only delete a course_id from the Course (parent) table, and all related records in the StudentCourse (child) table will also be deleted automatically by the database engine

Trang 12

A single input parameter course_id is passed into this stored procedure as the primary key

Now open this Web method and perform the modifi cations shown in Figure 9.146 to this Web method All modifi ed parts have been highlighted in bold

Let ’ s take a closer look at this piece of modifi ed code to see how it works.

A Change the name of this Web method from SQLDeleteSP to OracleDeleteSP and change

the returned data type from SQLBase to OracleBase

B The content of the query string is equal to the name of the stored procedure WebDeleteCourseSP we will develop in the next section Change the name of the stored procedure from dbo.WebDeleteCourseSP to WebDeleteCourseSP

C Change the prefi x from Sql to Oracle for all data classes and from sql to ora for all data objects used in this method Also change the name of the returned instance from SQLResult

to OracleResult Change the fi rst member data from SQLOK to OracleOK

D Change the name of the user - defi ned method from SQLConn to OracleConn Change the

second member data from SQLError to OracleError

E Modify the nominal name for the input parameter to the stored procedure by removing

the @ symbol before the nominal name CourseID Also change the data type of this input parameter from SqlDbType.Text to OracleType.VarChar

F Change the name of the returned instance from SQLResult to OracleResult Also change

the second member data from SQLError to OracleError and the prefi x from sql to ora for all data objects

[ WebMethod ] publicOracleBaseOracleDeleteSP(string CourseID) {

string cmdString = "WebDeleteCourseSP";

OracleConnectionoraConnection = newOracleConnection ();

OracleBaseOracleResult = newOracleBase ();

int intDelete = 0;

OracleResult.OracleOK = true ;

oraConnection = OracleConn();

if (oraConnection == null ) {

OracleResult.OracleError = "Database connection is failed";

ReportError(OracleResult);

return null ; }

OracleCommandoraCommand = newOracleCommand(cmdString, oraConnection);

oraCommand.CommandType = CommandType StoredProcedure;

oraCommand.Parameters.Add("CourseID", OracleType.VarChar).Value = CourseID;

intDelete = oraCommand.ExecuteNonQuery();

if (intDelete == 0) {

OracleResult.OracleError = "Data deleting is failed";

C

D

E

F WebServiceOracleUpdateDelete OracleDeleteSP()

Figure 9.146 Modifi ed Web method OracleDeleteSP

Trang 13

9.12.7.1 Develop Stored Procedure Web D elete C ourse SP

The topic we are discussing in this section is to delete data against the database

Therefore, no returned data is needed for this kind of data action, and we only need

to create stored procedures, not packages, in Oracle database to perform the data deleting function

As we discussed in Section 5.20.3.6 in Chapter 5 , different methods can be used to create Oracle ’ s stored procedures In this section, we will use the Object Browser page provided by Oracle Database 10g XE to create our stored procedures

Open the Oracle Database 10g XE home page by going to Start|All Programs|Oracle Database 10g Express Edition|Go To Database Home Page items Finish the login process by entering the correct username and password such as CSE_DEPT and reback Click on the Object Browser and select the Create|Procedures item to open the Create Procedure window Click on the Create button and select the Procedure icon from the list to open this window

Enter WebDeleteCourseSP into the Procedure Name box, keep the Include Argument checkbox checked, and click on the Next button to go to the next page The next window allows us to enter input parameters For this stored procedure we need only one input parameter CourseID Enter this input parameter into the argument box The point is that the data type of this input parameter must be identical with the data type of the data column course_id used in the Course table Refer to Section 2.11.2.3 in Chapter 2 to get a detailed list of data types used for those data columns in the Course data table

For the Input/Output parameters defi nition, select IN for this input parameter since

no output is needed for this data deleting query Your fi nished argument list should match that shown in Figure 9.147

Click on the Next button to go to the procedure defi ning page Enter the codes shown

in Figure 9.148 into this new procedure as the body of the procedure using the language

of so - called Procedural Language Extension for SQL or PL - SQL Then click on the Next and the Finish buttons to confi rm creation of this procedure Your fi nished stored pro- cedure should match that shown in Figure 9.149

Figure 9.147 Argument list

Trang 14

A single query is included in this procedure Because of the On Delete Cascade mode, as this query is executed, the record with a primary key course_id that equals

to the input parameter to this procedure in the Course (parent) table is deleted All records that have a foreign keycourse_id that is equal to the course_id in the Course table will also be deleted from the StudentCourse (child) table

To make sure that this procedure works properly, we need to compile it fi rst Click

on the Compile button to compile and check our procedure A successful compilation message should be displayed if our procedure is a bug - free stored procedure Close the Oracle Database 10g Express Edition by clicking on the Close button

At this point, we have fi nished all modifi cations to our new Web Service project WebServiceOracleUpdateDelete Now it is the time for us to run this project to test the data updating and deleting function

Figure 9.149 Completed coding body of the stored procedure

Figure 9.148 Coding body of the stored procedure

Trang 15

Figure 9.150 Running result of the Web method GetOracleCourseDetail

9.12.7.2 Implement and Test Web Service Project

Click on the Start Debugging button to run the project First, let ’ s test the Web method OracleUpdateSP() to update a course record CSE - 665 that is taught by the faculty member Ying Bai against our sample database To do that, let ’ s fi rst check the original detailed information of this course by running the Web method GetOracleCourseDetail()

by clicking on it from the opened built - in Web interface On the opened parameter - input page, enter CSE - 665 into the Value box as the course_id and click on the Invoke button to retrieve the detailed information for this course The running result of this method is shown in Figure 9.150

Keep in mind the detailed information for this course and let ’ s now try to update this course by running the Web method OracleUpdateSP() To do that, close the current running result page and click on The Back button to return to the initial Web page Click

on the Web method OracleUpdateSP to open its parameter - input page Enter the ing course information shown in Figure 9.151 into the associated Value boxes

Click on the Invoke button to run this method From the running result window, it can be found that the member data OracleOK is true , which means that this data updat- ing is successful Close the current running result window

To confi rm this course updating, click on the Back button to return to the initial page, and click on the Web method GetOracleCourseDetail to try to get back the detailed information for that updated course to validate this data updating Enter CSE - 665 into the CourseID box and click on the Invoke button to run this method The running result

of this method is shown in Figure 9.152 Compare this running result with the one shown

in Figure 9.150 It can be found that this course has been updated

Close the current running result window and click on the Back button to return to the initial page Next let ’ s test the Web method OracleDeleteSP()

Click on this method and enter a course_id for which you want to delete from the Course table, such as CSE - 665 , into the CourseID Value box, and click on the Invoke button to perform this data deleting It can be found from the running result that the member data OracleOK is true , which means that this data deleting is successful Close the current running result window

Ngày đăng: 14/12/2013, 15:15

TỪ KHÓA LIÊN QUAN