Outline Accessing SQL From a Programming Language Functions and Procedures ■Triggers ■Recursive Queries Advanced Aggregation Features Database System Concepts-7th Edition 5.2 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 5.2 ©Silberschatz, Korth and Sudarshan th Edition Outline ▪ Accessing SQL From a Programming Language ▪ Functions and Procedures ▪ Triggers ▪ Recursive Queries ▪ Advanced Aggregation Features
Accessing SQL from a Programming Language A database programmer must have access to a general-purpose programming language for at least two reasons Not all queries can be expressed in SQL,since SQL does not provide the full expressive power of a general-purpose language. 图 Non-declarative actions--such as printing a report,interacting with a user,or sending the results of a query to a graphical user interface-- cannot be done from within SQL. Database System Concepts-7th Edition 5.3 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 5.3 ©Silberschatz, Korth and Sudarshan th Edition Accessing SQL from a Programming Language ▪ Not all queries can be expressed in SQL, since SQL does not provide the full expressive power of a general-purpose language. ▪ Non-declarative actions -- such as printing a report, interacting with a user, or sending the results of a query to a graphical user interface -- cannot be done from within SQL. A database programmer must have access to a general-purpose programming language for at least two reasons
Accessing SQL from a Programming Language(Cont.) There are two approaches to accessing SQL from a general-purpose programming language A general-purpose program --can connect to and communicate with a database server using a collection of functions Embedded SQL--provides a means by which a program can interact with a database server. The SQL statements are translated at compile time into function calls. At runtime,these function calls connect to the database using an API that provides dynamic SQL facilities. Database System Concepts-7th Edition 5.4 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 5.4 ©Silberschatz, Korth and Sudarshan th Edition Accessing SQL from a Programming Language (Cont.) ▪ A general-purpose program -- can connect to and communicate with a database server using a collection of functions ▪ Embedded SQL -- provides a means by which a program can interact with a database server. • The SQL statements are translated at compile time into function calls. • At runtime, these function calls connect to the database using an API that provides dynamic SQL facilities. There are two approaches to accessing SQL from a general-purpose programming language
JDBC Database System Concepts-7th Edition 5.5 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 5.5 ©Silberschatz, Korth and Sudarshan th Edition JDBC
JDBC JDBC is a Java API for communicating with database systems supporting SQL. ■ JDBC supports a variety of features for querying and updating data,and for retrieving query results. JDBC also supports metadata retrieval,such as querying about relations present in the database and the names and types of relation attributes. Model for communicating with the database: ·Open a connection ·Create a“statement'”object Execute queries using the statement object to send queries and fetch results Exception mechanism to handle errors Database System Concepts-7th Edition 5.6 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 5.6 ©Silberschatz, Korth and Sudarshan th Edition JDBC ▪ JDBC is a Java API for communicating with database systems supporting SQL. ▪ JDBC supports a variety of features for querying and updating data, and for retrieving query results. ▪ JDBC also supports metadata retrieval, such as querying about relations present in the database and the names and types of relation attributes. ▪ Model for communicating with the database: • Open a connection • Create a “statement” object • Execute queries using the statement object to send queries and fetch results • Exception mechanism to handle errors