The document discusses different approaches for application development with databases, including embedded SQL, ODBC, and JDBC. Embedded SQL allows inserting SQL statements directly into host language code but requires a preprocessing step. ODBC provides a standard interface for connecting to different database systems but can be slow. JDBC is a Java database connectivity standard for writing Java database applications.
IJRET : International Journal of Research in Engineering and Technology is an international peer reviewed, online journal published by eSAT Publishing House for the enhancement of research in various disciplines of Engineering and Technology. The aim and scope of the journal is to provide an academic medium and an important reference for the advancement and dissemination of research results that support high-level learning, teaching and research in the fields of Engineering and Technology. We bring together Scientists, Academician, Field Engineers, Scholars and Students of related fields of Engineering and Technology
IJRET : International Journal of Research in Engineering and Technology is an international peer reviewed, online journal published by eSAT Publishing House for the enhancement of research in various disciplines of Engineering and Technology. The aim and scope of the journal is to provide an academic medium and an important reference for the advancement and dissemination of research results that support high-level learning, teaching and research in the fields of Engineering and Technology. We bring together Scientists, Academician, Field Engineers, Scholars and Students of related fields of Engineering and Technology
The Hacker Secret #2: The Dynamite of Next Generation (Y) Attack focus on client-side exploitation with Software bugs, latest windows vulnerabilities, etc...
The Hacker Secret #2: The Dynamite of Next Generation (Y) Attack focus on client-side exploitation with Software bugs, latest windows vulnerabilities, etc...
Embarcadero® Rapid SQL® is an award-winning SQL IDE giving database developers and DBAs
the ability to create high-performing SQL code on all major databases from a single interface.
The toolset simplifies SQL scripting, query building, object management, debugging, and version
control with easy-to-use, innovative tools.
This talk will focus on the real world benefits, features, architecture and ease of use of SQL Azure. Learn how your projects can benefit from a hosted data storage and query processing service. See by example how to design your program to use SQL Azure.
In this presentation we review SQL Azure Federation and Scalability.
Best Regards,
Dr. Eduardo Castro Martinez
Microsoft SQL Server MVP
http://ecastrom.blogspot.com
http://tinyurl.com/comunidadwindows
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Basic phrases for greeting and assisting costumers
Database Systems - Application Development
1. Application Development
SQL Facilities
Database Systems
Application Development
H. Turgut Uyar ¨ g¨ u u
Sule O˘ud¨c¨
¸
2002-2010
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
2. Application Development
SQL Facilities
License
¸ ¨ g¨ u u
c 2002-2010 T. Uyar, S. O˘ud¨c¨
You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work
Under the following conditions:
Attribution — You must attribute the work in the manner specified by the author or licensor (but not in
any way that suggests that they endorse you or your use of the work).
Noncommercial — You may not use this work for commercial purposes.
Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only
under the same or similar license to this one.
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
3. Application Development
SQL Facilities
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
4. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
5. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Introduction
using the database language in conjunction with a
general-purpose programming language
general-purpose language: host language
mismatch between SQL and the host language:
SQL operations on sets
iteration constructs in programming languages
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
6. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Introduction
using the database language in conjunction with a
general-purpose programming language
general-purpose language: host language
mismatch between SQL and the host language:
SQL operations on sets
iteration constructs in programming languages
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
7. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Program Structure
connect
server, database, username, password
as necessary:
execute a query
iterate over the result set
disconnect
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
8. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Program Structure
connect
server, database, username, password
as necessary:
execute a query
iterate over the result set
disconnect
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
9. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Program Structure
connect
server, database, username, password
as necessary:
execute a query
iterate over the result set
disconnect
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
10. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Approaches
application programming interface (API)
embedded SQL
ODBC
language standard interfaces
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
11. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Application Programming Interface
using the library functions of the SQL server
pros and cons:
fast
not standard
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
12. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Application Programming Interface
using the library functions of the SQL server
pros and cons:
fast
not standard
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
13. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
API Example
Example (PostgreSQL - C)
#i n c l u d e <l i b p q −f e . h>
i n t main ( v o i d )
{
/∗ c o n n e c t ∗/
/∗ e x e c u t e q u e r y ∗/
/∗ d i s c o n n e c t ∗/
}
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
14. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
API Example
Example (connecting)
/∗ PGconn ∗ conn ; ∗/
conn = PQconnectdb ( ”h o s t=l o c a l h o s t dbname=imdb ”
” u s e r=i t u c s p a s s w o r d=i t u c s ” ) ;
i f ( P Q s t a t u s ( conn ) == CONNECTION BAD) {
f p r i n t f ( s t d e r r , ”C o n n e c t i o n f a i l e d . n ” ) ;
exit (1);
}
/∗ e x e c u t e q u e r y ∗/
P Q f i n i s h ( conn ) ;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
15. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
API Example
Example (executing a query)
/∗ P G r e s u l t ∗ r e s u l t ; ∗/
s p r i n t f ( q u e r y , ”SELECT TITLE , SCORE ”
” FROM MOVIE WHERE (YR = %d ) ” , y e a r ) ;
r e s u l t = PQexec ( conn , q u e r y ) ;
i f ( P Q r e s u l t S t a t u s ( r e s u l t ) != PGRES TUPLES OK ) {
f p r i n t f ( s t d e r r , ”Query f a i l e d . n ” ) ;
PQclear ( r e s u l t ) ;
P Q f i n i s h ( conn ) ;
exit (1);
}
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
16. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
API Example
Example (processing the result set)
f o r ( i = 0 ; i < P Q n t u p l e s ( r e s u l t ) ; i ++)
p r i n t f ( ”%s %s n ” ,
PQgetvalue ( r e s u l t , i , 0) ,
PQgetvalue ( r e s u l t , i , 1 ) ) ;
PQclear ( r e s u l t ) ;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
17. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
18. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL
stages:
1 mark SQL statements within host language code:
EXEC SQL
2 embedded SQL preprocessor:
embedded SQL directives → API calls
3 host language compiler
pros and cons:
fast, standard
difficult, does not support most languages
skip Embedded SQL
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
19. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL
stages:
1 mark SQL statements within host language code:
EXEC SQL
2 embedded SQL preprocessor:
embedded SQL directives → API calls
3 host language compiler
pros and cons:
fast, standard
difficult, does not support most languages
skip Embedded SQL
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
20. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
21. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL Standard
sharing variables with the host language
error control
adapting query results
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
22. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Variable Sharing
Syntax
EXEC SQL BEGIN DECLARE SECTION ;
shared v a r i a b l e s
EXEC SQL END DECLARE SECTION ;
in SQL statements: ’:’ in front of host language variables
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
23. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Error Control
Error Processing
EXEC SQL WHENEVER
{ SQLERROR | SQLWARNING | NOT FOUND }
{ STOP | CONTINUE | DO command | GOTO l a b e l }
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
24. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Adapting Query Results
Cursors
EXEC SQL DECLARE c u r s o r n a m e CURSOR FOR SELECT . . .
EXEC SQL OPEN c u r s o r n a m e ;
EXEC SQL FETCH IN c u r s o r n a m e INTO v a r i a b l e s ;
EXEC SQL CLOSE c u r s o r n a m e ;
query is not executed when cursor is defined
it is executed when cursor is opened
cursor points to first element in the result set
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
25. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Adapting Query Results
Cursors
EXEC SQL DECLARE c u r s o r n a m e CURSOR FOR SELECT . . .
EXEC SQL OPEN c u r s o r n a m e ;
EXEC SQL FETCH IN c u r s o r n a m e INTO v a r i a b l e s ;
EXEC SQL CLOSE c u r s o r n a m e ;
query is not executed when cursor is defined
it is executed when cursor is opened
cursor points to first element in the result set
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
26. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL Example
Example (connecting)
EXEC SQL BEGIN DECLARE SECTION ;
int yr ;
char ∗ t i t l e = NULL , ∗ s c o r e = NULL ;
EXEC SQL END DECLARE SECTION ;
EXEC SQL CONNECT TO i t u c s
USER i t u c s IDENTIFIED BY i t u c s ;
/∗ p r o c e s s q u e r y ∗/
EXEC SQL DISCONNECT ;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
27. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL Example
Example (processing query)
s c a n f ( ”%d ” , &y r ) ;
EXEC SQL DECLARE c q u e r y CURSOR FOR
SELECT TITLE , SCORE FROM MOVIE
WHERE (YR = : y r ) ;
EXEC SQL OPEN c q u e r y ;
/∗ e x e c u t e q u e r y ∗/
EXEC SQL CLOSE c q u e r y ;
EXEC SQL COMMIT;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
28. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Embedded SQL Example
Example (executing query)
EXEC SQL WHENEVER NOT FOUND DO break ;
while (1) {
EXEC SQL FETCH c q u e r y INTO : t i t l e , : s c o r e ;
p r i n t f ( ”%s %s n ” , t i t l e , s c o r e ) ;
t i t l e = s c o r e = NULL ;
}
free ( t i t l e );
free ( score );
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
29. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
30. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC
ODBC: Open DataBase Connectivity:
a service layer between the application and the server
pros and cons:
standard
very slow
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
31. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC
ODBC: Open DataBase Connectivity:
a service layer between the application and the server
pros and cons:
standard
very slow
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
32. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC Architecture
application
driver manager
registers the ODBC drivers
transfers requests from application to driver
driver
translates and transfers requests to data source
data source
processes instructions from the driver
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
33. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC Architecture
application
driver manager
registers the ODBC drivers
transfers requests from application to driver
driver
translates and transfers requests to data source
data source
processes instructions from the driver
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
34. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC Architecture
application
driver manager
registers the ODBC drivers
transfers requests from application to driver
driver
translates and transfers requests to data source
data source
processes instructions from the driver
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
35. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC Architecture
application
driver manager
registers the ODBC drivers
transfers requests from application to driver
driver
translates and transfers requests to data source
data source
processes instructions from the driver
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
36. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC Example
Example (PHP)
$conn = odbc connect ( ”imdb ” , ” i t u c s ” , ” i t u c s ” ) ;
$ q u e r y = ”SELECT TITLE , SCORE ”
” FROM MOVIE WHERE (YR = ” . $ y e a r . ”) ” ;
$ r e s u l t = odbc exec ( $conn , $ q u e r y ) ;
/∗ p r o c e s s t h e r e s u l t s e t ∗/
o d b c c l o s e ( $conn ) ;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
37. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
ODBC Example
Example (processing the result set)
echo ”<t a b l e >n ” ;
w h i l e ( odbc fetch row ( $ r e s u l t ) ) {
$ t i t l e = odbc result ( $result , ” t i t l e ”) ;
$ s c o r e = o d b c r e s u l t ( $ r e s u l t , ”s c o r e ” ) ;
echo ”<t r >n ” ;
echo ” <td>$ t i t l e </td >n ” ;
echo ” <td>$ s c o r e </td >n ” ;
echo ”</ t r >n ” ;
}
echo ”</ t a b l e >n ” ;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
38. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
39. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC
JDBC: Java DataBase Connectivity
same architectural concepts as in ODBC
different types of drivers
JDBC URL for connection
jdbc:<subprotocol>:<otherParameters>
matching Java and SQL data types
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
40. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC
JDBC: Java DataBase Connectivity
same architectural concepts as in ODBC
different types of drivers
JDBC URL for connection
jdbc:<subprotocol>:<otherParameters>
matching Java and SQL data types
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
41. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC
JDBC: Java DataBase Connectivity
same architectural concepts as in ODBC
different types of drivers
JDBC URL for connection
jdbc:<subprotocol>:<otherParameters>
matching Java and SQL data types
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
42. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC
JDBC: Java DataBase Connectivity
same architectural concepts as in ODBC
different types of drivers
JDBC URL for connection
jdbc:<subprotocol>:<otherParameters>
matching Java and SQL data types
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
43. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Drivers
Type I: bridges
translate into non-native calls (for example ODBC)
Type II: direct translation via non-Java driver
translate into API of data source (for example C++)
Type III: network bridges
connect to middleware server for translating into API of data
source
Type IV: direct translation via Java driver
communicate with DBMS through Java sockets
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
44. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Drivers
Type I: bridges
translate into non-native calls (for example ODBC)
Type II: direct translation via non-Java driver
translate into API of data source (for example C++)
Type III: network bridges
connect to middleware server for translating into API of data
source
Type IV: direct translation via Java driver
communicate with DBMS through Java sockets
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
45. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Drivers
Type I: bridges
translate into non-native calls (for example ODBC)
Type II: direct translation via non-Java driver
translate into API of data source (for example C++)
Type III: network bridges
connect to middleware server for translating into API of data
source
Type IV: direct translation via Java driver
communicate with DBMS through Java sockets
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
46. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Drivers
Type I: bridges
translate into non-native calls (for example ODBC)
Type II: direct translation via non-Java driver
translate into API of data source (for example C++)
Type III: network bridges
connect to middleware server for translating into API of data
source
Type IV: direct translation via Java driver
communicate with DBMS through Java sockets
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
47. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Package
import the JDBC package:
import java . sql .∗
exception about SQL operations:
SQLException
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
48. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Package
import the JDBC package:
import java . sql .∗
exception about SQL operations:
SQLException
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
49. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Connection
DriverManager: connection manager
getConnection (static)
Connection: database connection
createStatement
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
50. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Connection
DriverManager: connection manager
getConnection (static)
Connection: database connection
createStatement
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
51. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Queries
Statement: SQL statement
executeQuery: for query operations
executeUpdate: for insert/update/delete operations
PreparedStatement: precompiled SQL statement
can be used multiple times
placeholder for parameters: ?
set value before invoking query
ResultSet: set of query results
next: next element in the result set
methods for getting the data in appropriate type
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
52. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Queries
Statement: SQL statement
executeQuery: for query operations
executeUpdate: for insert/update/delete operations
PreparedStatement: precompiled SQL statement
can be used multiple times
placeholder for parameters: ?
set value before invoking query
ResultSet: set of query results
next: next element in the result set
methods for getting the data in appropriate type
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
53. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Queries
Statement: SQL statement
executeQuery: for query operations
executeUpdate: for insert/update/delete operations
PreparedStatement: precompiled SQL statement
can be used multiple times
placeholder for parameters: ?
set value before invoking query
ResultSet: set of query results
next: next element in the result set
methods for getting the data in appropriate type
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
54. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
Java and SQL Data Types
SQL type Java class ResultSet method
BIT Boolean getBoolean()
CHAR String getString()
VARCHAR String getString()
DOUBLE Double getDouble()
FLOAT Float getDouble()
INTEGER Integer getInt()
REAL Double getFloat()
DATE java.sql.Date getDate()
TIME java.sql.Time getTime()
TIMESTAMP java.sql.TimeStamp getTimestamp()
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
55. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Example
Example (checking the database driver)
try {
C l a s s . forName ( ”o r g . p o s t g r e s q l . D r i v e r ” ) ;
} catch ( C l a s s N o t F o u n d E x c e p t i o n e ) {
// PostgreSQL d r i v e r n o t i n s t a l l e d
}
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
56. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Example
Example (connecting)
try {
C o n n e c t i o n conn = D r i v e r M a n a g e r . g e t C o n n e c t i o n (
”j d b c : p o s t g r e s q l : imdb ” , ” i t u c s ” , ” i t u c s ”
);
} catch ( SQLExce ptio n e ) {
// c o n n e c t i o n e r r o r
}
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
57. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Example
Example (executing query)
S t a t e m e n t st mt = conn . c r e a t e S t a t e m e n t ( ) ;
S t r i n g q u e r y = ”SELECT TITLE , SCORE FROM MOVIE ”
+ ” WHERE (YR = 1 9 9 0 ) ” ;
R e s u l t S e t r e s u l t = stmt . executeQuery ( query ) ;
while ( r e s u l t . next ( ) )
System . o u t . p r i n t l n ( r e s u l t . g e t S t r i n g ( 1 )
+ ” ” + result . getFloat (2));
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
58. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
JDBC Example
Example (prepared statement)
S t r i n g q u e r y = ”DELETE FROM MOVIE ” +
” WHERE (SCORE < ? ) ” ;
PreparedStatement stmt =
conn . p r e p a r e S t a t e m e n t ( q u e r y ) ;
stmt . s e t F l o a t (1 , s c o r e ) ;
stmt . executeUpdate ( ) ;
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
59. Introduction
Embedded SQL
Application Development
ODBC
SQL Facilities
JDBC
References
References
Required text: Ramakrishnan, Gehrke
Chapter 6: Database Application Development
6.1. Accessing Databases from Applications
6.2. An Introduction to JDBC
6.3. JDBC Classes and Interfaces
Supplementary text: Date
Chapter 4: An Introduction to SQL
4.6. Embedded SQL
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
60. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
61. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Stored Procedures
implementing functionality in the database server
languages: SQL, PL/SQL, C, ...
not really recommended
not portable
database servers are not optimized for business logic
→ implement business logic on the application server
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
62. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Stored Procedures
implementing functionality in the database server
languages: SQL, PL/SQL, C, ...
not really recommended
not portable
database servers are not optimized for business logic
→ implement business logic on the application server
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
63. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Functions
SQL Statement
CREATE FUNCTION f u n c t i o n n a m e ( [ type [ , ...]])
RETURNS r e t u r n t y p e
AS f u n c t i o n b o d y
LANGUAGE l a n g u a g e n a m e
first parameter $1, second parameter $2, ...
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
64. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Functions
SQL Statement
CREATE FUNCTION f u n c t i o n n a m e ( [ type [ , ...]])
RETURNS r e t u r n t y p e
AS f u n c t i o n b o d y
LANGUAGE l a n g u a g e n a m e
first parameter $1, second parameter $2, ...
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
65. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
SQL Function Example
Example (calculating new score)
$1: old score, $2: old votes, $3: new vote
CREATE FUNCTION NEW SCORE( f l o a t , i n t , i n t )
RETURNS f l o a t
AS ’ SELECT ( $1 ∗ $2+$3 ) / ( $2 +1); ’
LANGUAGE ’ s q l ’
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
66. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Triggers
Definition
trigger:
a function that will be automatically activated on an event
can be useful for maintaining integrity
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
67. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Triggers
SQL Statement
CREATE TRIGGER t r i g g e r n a m e
{ BEFORE | AFTER } { e v e n t [ OR . . . ] }
ON t a b l e n a m e
[ FOR [ EACH ] { ROW | STATEMENT } ]
EXECUTE PROCEDURE f u n c t i o n n a m e ( . . . )
PL/pgSQL:
old: tuple before the operation
new: tuple after the operation
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
68. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Triggers
SQL Statement
CREATE TRIGGER t r i g g e r n a m e
{ BEFORE | AFTER } { e v e n t [ OR . . . ] }
ON t a b l e n a m e
[ FOR [ EACH ] { ROW | STATEMENT } ]
EXECUTE PROCEDURE f u n c t i o n n a m e ( . . . )
PL/pgSQL:
old: tuple before the operation
new: tuple after the operation
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
69. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Trigger Example
Example (keep a ”points” column)
CREATE FUNCTION UPDATE MOVIE POINTS ( )
RETURNS opaque
AS ’ BEGIN
new . POINTS = new . SCORE ∗ new . VOTES ;
RETURN new ;
END ; ’
LANGUAGE ’ p l p g s q l ’
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
70. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Trigger Example
Example (keep a ”points” column)
CREATE TRIGGER UPDATE MOVIE
BEFORE INSERT OR UPDATE ON MOVIE
FOR EACH ROW
EXECUTE PROCEDURE UPDATE MOVIE POINTS ( )
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
71. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
72. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Views
presenting a derived table like a base table
isolating application programs from changes in database
structure
denormalizing after database refactoring
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
73. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Views
presenting a derived table like a base table
isolating application programs from changes in database
structure
denormalizing after database refactoring
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
74. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Views
SQL Statement
CREATE VIEW view name AS
SELECT . . .
the SELECT query will be executed every time the view is used
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
75. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Views
SQL Statement
CREATE VIEW view name AS
SELECT . . .
the SELECT query will be executed every time the view is used
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
76. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
View Example
Example
CREATE VIEW NEW MOVIE AS
SELECT ID , TITLE , YR FROM MOVIE
WHERE (YR > 1 9 9 5 )
SELECT ∗ FROM NEW MOVIE
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
77. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
View Example
Example
CREATE VIEW NEW MOVIE AS
SELECT ID , TITLE , YR FROM MOVIE
WHERE (YR > 1 9 9 5 )
SELECT ∗ FROM NEW MOVIE
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
78. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Updating Views
changes have to performed on the base tables
rules are needed
Creating Rules
CREATE RULE r u l e n a m e AS
ON e v e n t TO view name
[ WHERE c o n d i t i o n ]
DO [ INSTEAD ] s q l s t a t e m e n t
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
79. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Updating Views
changes have to performed on the base tables
rules are needed
Creating Rules
CREATE RULE r u l e n a m e AS
ON e v e n t TO view name
[ WHERE c o n d i t i o n ]
DO [ INSTEAD ] s q l s t a t e m e n t
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
80. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
View Rule Example
Example
UPDATE NEW MOVIE SET TITLE= ’ . . ’
WHERE ( ID = 1 )
CREATE RULE UPDATE TITLE AS
ON UPDATE TO NEW MOVIE
DO INSTEAD
UPDATE MOVIE SET TITLE = new . TITLE
WHERE ( ID = o l d . ID )
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
81. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
View Rule Example
Example
UPDATE NEW MOVIE SET TITLE= ’ . . ’
WHERE ( ID = 1 )
CREATE RULE UPDATE TITLE AS
ON UPDATE TO NEW MOVIE
DO INSTEAD
UPDATE MOVIE SET TITLE = new . TITLE
WHERE ( ID = o l d . ID )
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
82. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Snapshots
similar to view but creates a new base table
the query is executed only once when snapshot is created
changes to base tables do not effect the snapshot
no updates on the snapshot
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
83. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Snapshots
similar to view but creates a new base table
the query is executed only once when snapshot is created
changes to base tables do not effect the snapshot
no updates on the snapshot
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
84. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Creating Snapshots
SQL Statement
CREATE SNAPSHOT s n a p s h o t n a m e AS
SELECT . . .
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
85. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
86. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Permissions
subject: active entities (user, group)
object: passive entities (table, column, view, ...)
owner of object determines permissions of other subjects:
discretionary access control
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
87. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Permissions
subject: active entities (user, group)
object: passive entities (table, column, view, ...)
owner of object determines permissions of other subjects:
discretionary access control
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
88. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
SQL Permissions
Granting Permissions
GRANT p e r m i s s i o n n a m e [ , . . . ]
ON o b j e c t n a m e TO s u b j e c t n a m e
[ WITH GRANT OPTION ]
Revoking Permissions
REVOKE p e r m i s s i o n n a m e
ON o b j e c t n a m e FROM s u b j e c t n a m e
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
89. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
SQL Permissions
Granting Permissions
GRANT p e r m i s s i o n n a m e [ , . . . ]
ON o b j e c t n a m e TO s u b j e c t n a m e
[ WITH GRANT OPTION ]
Revoking Permissions
REVOKE p e r m i s s i o n n a m e
ON o b j e c t n a m e FROM s u b j e c t n a m e
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
90. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Permission Examples
Example (granting permissions on a table)
GRANT SELECT, INSERT , UPDATE ON MOVIE TO ’ i t u c s ’
Example (granting permissions on a view)
GRANT SELECT ON NEW MOVIES TO ’ i t u c s ’
Example (revoking permissions on a table)
REVOKE INSERT ON MOVIE FROM ’ i t u c s ’
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
91. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Permission Examples
Example (granting permissions on a table)
GRANT SELECT, INSERT , UPDATE ON MOVIE TO ’ i t u c s ’
Example (granting permissions on a view)
GRANT SELECT ON NEW MOVIES TO ’ i t u c s ’
Example (revoking permissions on a table)
REVOKE INSERT ON MOVIE FROM ’ i t u c s ’
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
92. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Permission Examples
Example (granting permissions on a table)
GRANT SELECT, INSERT , UPDATE ON MOVIE TO ’ i t u c s ’
Example (granting permissions on a view)
GRANT SELECT ON NEW MOVIES TO ’ i t u c s ’
Example (revoking permissions on a table)
REVOKE INSERT ON MOVIE FROM ’ i t u c s ’
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
93. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Topics
1 Application Development
Introduction
Embedded SQL
ODBC
JDBC
2 SQL Facilities
Stored Procedures
Views
Permissions
Performance
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
94. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Indexes
some operations require sorting:
ORDER BY, DISTINCT, GROUP BY, UNION, ...
creating indexes can speed up queries
slows and insert and update operations
every key definition creates an index
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
95. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Indexes
some operations require sorting:
ORDER BY, DISTINCT, GROUP BY, UNION, ...
creating indexes can speed up queries
slows and insert and update operations
every key definition creates an index
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
96. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
Indexes
SQL Statement
CREATE [ UNIQUE ] INDEX i n d e x n a m e
ON t a b l e n a m e ( column name [ , . . . ] )
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems
97. Stored Procedures
Views
Application Development
Permissions
SQL Facilities
Performance
References
References
Required text: Date
Chapter 9: Integrity
9.11. Triggers (a Digression)
Chapter 10: Views
Chapter 17: Security
17.1. Introduction
17.6. SQL Facilities
¸ ¨ g¨ u u
H. Turgut Uyar, Sule O˘ud¨c¨ Database Systems