SlideShare a Scribd company logo
3
Approaches?
• Dynamic SQL
• Embedded SQL
Most read
4
Standards and API’s for Data Access
• ODBC
• OLE-DB
• JDBC
• ADO/ADO.NET
• LINQ ?
• ODMG Standards (CORBA, …)
• DB-Lib
• HTTP/SOAP
• …
Most read
16
Whole Business logic written in SQL?
Most read
Accessing Databases From Programming Languages
Database Systems Course
S.Shayan Daneshvar 5.1, 5.2 – 24.4
Why?
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!
• 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.
Approaches?
• Dynamic SQL
• Embedded SQL
Standards and API’s for Data Access
• ODBC
• OLE-DB
• JDBC
• ADO/ADO.NET
• LINQ ?
• ODMG Standards (CORBA, …)
• DB-Lib
• HTTP/SOAP
• …
ODBC?
Open Database Connectivity:
The ODBC standard is a widely used standard for communication between client
applications and database systems. ODBC is based on the SQL Call Level Interface
(CLI) standards developed by the X/Open industry consortium and the SQL Access
Group, but it has several extensions.The ODBC API defines a CLI, an SQL syntax
definition, and rules about permissible sequences of CLI calls.
ODBC allows a client to connect simultaneously to multiple data sources and to
switch among them, but transactions on each are independent; ODBC does not
support two-phase commit.
The Open Database Connectivity (ODBC) standard defines an API that applications
can use to open a connection with a database, send queries and updates, and get
back results.
ODBC Example (C/C++)
void ODBCexample()
{
RETCODE error;
HENV env; /* environment */
HDBC conn; /* database connection */
SQLAllocEnv(&env);
SQLAllocConnect(env, &conn);
SQLConnect(conn, "db.kntu.edu", SQL
NTS, "avi", SQL NTS, "avipasswd", SQL
NTS);
{
char deptname[80];
float salary;
int lenOut1, lenOut2;
HSTMT stmt;
char * sqlquery = "select dept name, sum (salary)
from instructor
group by dept name";
SQLAllocStmt(conn, &stmt);
error = SQLExecDirect(stmt, sqlquery, SQL NTS);
if (error == SQL SUCCESS) {
SQLBindCol(stmt, 1, SQL C CHAR, deptname , 80, &lenOut1);
SQLBindCol(stmt, 2, SQL C FLOAT, &salary, 0 , &lenOut2);
while (SQLFetch(stmt) == SQL SUCCESS) {
printf (" %s %gn", depthname, salary);
}
}
SQLFreeStmt(stmt, SQL DROP);
}
SQLDisconnect(conn);
SQLFreeConnect(conn);
SQLFreeEnv(env);
}
ADO and ADO.NET
The Active Data Objects (ADO) API, also created by Microsoft, provides an easy-to-
use interface to the OLE-DB functionality, which can be called from scripting
languages, such asVBScript and JScript.
The newer ADO.NET API is designed for applications written in the .NET languages
such as C# andVisual Basic.NET. In addition to providing simplified interfaces, it
provides an abstraction called the DataSet that permits disconnected data access.
Example: ?
OLE-DB
There are many data sources that are not relational databases, and in fact may not
be databases at all. Examples are flat files and email stores.
Microsoft’s OLE-DB is a C++ API with goals similar to ODBC, but for non-database
data sources that may provide only limited querying and update facilities.
Just like ODBC, OLE-DB provides constructs for connecting to a data source,
starting a session, executing commands, and getting back results in the form of a
rowset, which is a set of result rows. However, OLE-DB differs from ODBC in several
ways ….
JDBC?
Java Database Connectivity:
The JDBC standard defines an application program interface (API) that Java
programs can use to connect to database servers.
The JDBCAPI consists of a set of interfaces and classes written in the Java
programming language.
JDBC is used in languages that use the JVM.
JVM Languages: Java, Kotlin, Scala, Groovy, Clojure, …
Simple JDBC Example
Simple JDBC Example…
JDBC in Details
• Statement
executeQuery()  ResultSet //Query: Select * from Students
executeUpdate()  long // NonQuery: Insert – Delete - Create – Update - …
• Prepared Statement
• Callable Statement
SQL Injection!
Query: "select * from instructor where name = ’" + name + "’“
User Input: X’ or ’Y’ = ’Y
Final Query:
select * from instructor where name = ’X’ or ’Y’ = ’Y’
Solution ?
• Prepared Statement : select * from instructor where name = ’X’ or ’Y’ = ’Y’
• ?
Functions, ProceduresAndTriggers
SQL allows the definition of functions, procedures, and methods.
Note that databases usually have their own notation for stored procedures/functions!
(PL/SQL, T-SQL, PL/pgsql, …)
Standard SQL Example (Function):
Stored Procedures
Standard SQL Example:
Calling Stored Procedures:
PSM (Persistence Storage Module)?
Whole Business logic written in SQL?
Triggers? Methods?
Will talk about them in more details later!
But know that …
Also know that some databases support writing methods in them with a
programming language. IBM DB2 & Oracle support Java Methods.
Back to JDBC
• Callable Statement
CallableStatement cStmt1 = conn.prepareCall("{? = call some function(?)}");
CallableStatement cStmt2 = conn.prepareCall("{call some procedure(?,?)}");
The data types of function return values and out parameters of procedures must be
registered using the method registerOutParameter(), and can be retrieved using get
methods similar to those for result sets. See a JDBC manual for more details.
Other Features
• Metadata Features
• Updatable ResultSet
• Transactional Features (setAutoCommit())
Read About these features in Database Systems Book by Silberschats , …
Embedded SQL
We are not going to talk much about embedded SQL since it is not widely used!
But in Java we have SQLJ!
…
Architectural and Design Patterns
• Repository Architectural Pattern
• DAO
• …
Related Patterns:
• Facade
• …
Mapping? ORM? ODM? ….
• Hibernate, Eclipse Link, OpenJPA, … (Java Persistence API)
• Entity Framework, Nhibernate
• …
Version Control for Database?
• MigrationTools
• Flyway
• Liquibase
• ..

More Related Content

What's hot (20)

Architecture business cycle
Architecture business cycleArchitecture business cycle
Architecture business cycle
Himanshu
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http response
Nuha Noor
 
Case study of amazon EC2 by Akash Badone
Case study of amazon EC2 by Akash BadoneCase study of amazon EC2 by Akash Badone
Case study of amazon EC2 by Akash Badone
Akash Badone
 
Use case diagrams
Use case diagramsUse case diagrams
Use case diagrams
mohamed tahoon
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 
Requirements elicitation
Requirements elicitationRequirements elicitation
Requirements elicitation
Syed Zaid Irshad
 
Basic Block Scheduling
Basic Block SchedulingBasic Block Scheduling
Basic Block Scheduling
NilaNila16
 
Data definition language
Data definition languageData definition language
Data definition language
VENNILAV6
 
Cloud Computing and Service oriented Architecture
Cloud Computing and Service oriented Architecture Cloud Computing and Service oriented Architecture
Cloud Computing and Service oriented Architecture
Ravindra Dastikop
 
Object Oriented Database Management System
Object Oriented Database Management SystemObject Oriented Database Management System
Object Oriented Database Management System
Ajay Jha
 
Introduction to files and db systems 1.0
Introduction to files and db systems 1.0Introduction to files and db systems 1.0
Introduction to files and db systems 1.0
Dr. C.V. Suresh Babu
 
Transaction management in DBMS
Transaction management in DBMSTransaction management in DBMS
Transaction management in DBMS
Megha Sharma
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
koolkampus
 
Distributed database
Distributed databaseDistributed database
Distributed database
ReachLocal Services India
 
relational algebra
relational algebrarelational algebra
relational algebra
Shashank Singh
 
Database Administration
Database AdministrationDatabase Administration
Database Administration
Bilal Arshad
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
koolkampus
 
Database administrator
Database administratorDatabase administrator
Database administrator
Tech_MX
 
Distributed Database Management System
Distributed Database Management SystemDistributed Database Management System
Distributed Database Management System
Hardik Patil
 
Architecture business cycle
Architecture business cycleArchitecture business cycle
Architecture business cycle
Himanshu
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http response
Nuha Noor
 
Case study of amazon EC2 by Akash Badone
Case study of amazon EC2 by Akash BadoneCase study of amazon EC2 by Akash Badone
Case study of amazon EC2 by Akash Badone
Akash Badone
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 
Basic Block Scheduling
Basic Block SchedulingBasic Block Scheduling
Basic Block Scheduling
NilaNila16
 
Data definition language
Data definition languageData definition language
Data definition language
VENNILAV6
 
Cloud Computing and Service oriented Architecture
Cloud Computing and Service oriented Architecture Cloud Computing and Service oriented Architecture
Cloud Computing and Service oriented Architecture
Ravindra Dastikop
 
Object Oriented Database Management System
Object Oriented Database Management SystemObject Oriented Database Management System
Object Oriented Database Management System
Ajay Jha
 
Introduction to files and db systems 1.0
Introduction to files and db systems 1.0Introduction to files and db systems 1.0
Introduction to files and db systems 1.0
Dr. C.V. Suresh Babu
 
Transaction management in DBMS
Transaction management in DBMSTransaction management in DBMS
Transaction management in DBMS
Megha Sharma
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
koolkampus
 
Database Administration
Database AdministrationDatabase Administration
Database Administration
Bilal Arshad
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
koolkampus
 
Database administrator
Database administratorDatabase administrator
Database administrator
Tech_MX
 
Distributed Database Management System
Distributed Database Management SystemDistributed Database Management System
Distributed Database Management System
Hardik Patil
 

Similar to Advanced SQL - Database Access from Programming Languages (20)

Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
Tech_MX
 
Jdbc
JdbcJdbc
Jdbc
Yamuna Devi
 
Presentation for java data base connectivity
Presentation for java data base connectivityPresentation for java data base connectivity
Presentation for java data base connectivity
kanjariya006
 
DBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptxDBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptx
SRAHUL23
 
11. jdbc
11. jdbc11. jdbc
11. jdbc
Rajesh Roky
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
kunj desai
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
Sasidhar Kothuru
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
chhaichivon
 
Jdbc
JdbcJdbc
Jdbc
Nitesh Kumar Pandey
 
03-JDBC.pptx
03-JDBC.pptx03-JDBC.pptx
03-JDBC.pptx
HachaluHaile
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Jdbc
JdbcJdbc
Jdbc
Indu Lata
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
Hemo Chella
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
yazidds2
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
SivaSankari36
 
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc pptjdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
Indu32
 
Jdbc
JdbcJdbc
Jdbc
Mallikarjuna G D
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
Tech_MX
 
Presentation for java data base connectivity
Presentation for java data base connectivityPresentation for java data base connectivity
Presentation for java data base connectivity
kanjariya006
 
DBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptxDBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptx
SRAHUL23
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
kunj desai
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
chhaichivon
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
yazidds2
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
SivaSankari36
 
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc pptjdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
Indu32
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Ad

More from S.Shayan Daneshvar (8)

Image to image translation with Pix2Pix GAN
Image to image translation with Pix2Pix GANImage to image translation with Pix2Pix GAN
Image to image translation with Pix2Pix GAN
S.Shayan Daneshvar
 
Microservice architecture (MSA) and patterns
Microservice architecture (MSA) and patternsMicroservice architecture (MSA) and patterns
Microservice architecture (MSA) and patterns
S.Shayan Daneshvar
 
PostgreSQL - Case Study
PostgreSQL - Case StudyPostgreSQL - Case Study
PostgreSQL - Case Study
S.Shayan Daneshvar
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
S.Shayan Daneshvar
 
Longest increasing subsequence
Longest increasing subsequenceLongest increasing subsequence
Longest increasing subsequence
S.Shayan Daneshvar
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
S.Shayan Daneshvar
 
Amortized analysis
Amortized analysisAmortized analysis
Amortized analysis
S.Shayan Daneshvar
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
S.Shayan Daneshvar
 
Image to image translation with Pix2Pix GAN
Image to image translation with Pix2Pix GANImage to image translation with Pix2Pix GAN
Image to image translation with Pix2Pix GAN
S.Shayan Daneshvar
 
Microservice architecture (MSA) and patterns
Microservice architecture (MSA) and patternsMicroservice architecture (MSA) and patterns
Microservice architecture (MSA) and patterns
S.Shayan Daneshvar
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
S.Shayan Daneshvar
 
Longest increasing subsequence
Longest increasing subsequenceLongest increasing subsequence
Longest increasing subsequence
S.Shayan Daneshvar
 
Ad

Recently uploaded (20)

Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 

Advanced SQL - Database Access from Programming Languages

  • 1. Accessing Databases From Programming Languages Database Systems Course S.Shayan Daneshvar 5.1, 5.2 – 24.4
  • 2. Why? 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! • 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.
  • 4. Standards and API’s for Data Access • ODBC • OLE-DB • JDBC • ADO/ADO.NET • LINQ ? • ODMG Standards (CORBA, …) • DB-Lib • HTTP/SOAP • …
  • 5. ODBC? Open Database Connectivity: The ODBC standard is a widely used standard for communication between client applications and database systems. ODBC is based on the SQL Call Level Interface (CLI) standards developed by the X/Open industry consortium and the SQL Access Group, but it has several extensions.The ODBC API defines a CLI, an SQL syntax definition, and rules about permissible sequences of CLI calls. ODBC allows a client to connect simultaneously to multiple data sources and to switch among them, but transactions on each are independent; ODBC does not support two-phase commit. The Open Database Connectivity (ODBC) standard defines an API that applications can use to open a connection with a database, send queries and updates, and get back results.
  • 6. ODBC Example (C/C++) void ODBCexample() { RETCODE error; HENV env; /* environment */ HDBC conn; /* database connection */ SQLAllocEnv(&env); SQLAllocConnect(env, &conn); SQLConnect(conn, "db.kntu.edu", SQL NTS, "avi", SQL NTS, "avipasswd", SQL NTS); { char deptname[80]; float salary; int lenOut1, lenOut2; HSTMT stmt; char * sqlquery = "select dept name, sum (salary) from instructor group by dept name"; SQLAllocStmt(conn, &stmt); error = SQLExecDirect(stmt, sqlquery, SQL NTS); if (error == SQL SUCCESS) { SQLBindCol(stmt, 1, SQL C CHAR, deptname , 80, &lenOut1); SQLBindCol(stmt, 2, SQL C FLOAT, &salary, 0 , &lenOut2); while (SQLFetch(stmt) == SQL SUCCESS) { printf (" %s %gn", depthname, salary); } } SQLFreeStmt(stmt, SQL DROP); } SQLDisconnect(conn); SQLFreeConnect(conn); SQLFreeEnv(env); }
  • 7. ADO and ADO.NET The Active Data Objects (ADO) API, also created by Microsoft, provides an easy-to- use interface to the OLE-DB functionality, which can be called from scripting languages, such asVBScript and JScript. The newer ADO.NET API is designed for applications written in the .NET languages such as C# andVisual Basic.NET. In addition to providing simplified interfaces, it provides an abstraction called the DataSet that permits disconnected data access. Example: ?
  • 8. OLE-DB There are many data sources that are not relational databases, and in fact may not be databases at all. Examples are flat files and email stores. Microsoft’s OLE-DB is a C++ API with goals similar to ODBC, but for non-database data sources that may provide only limited querying and update facilities. Just like ODBC, OLE-DB provides constructs for connecting to a data source, starting a session, executing commands, and getting back results in the form of a rowset, which is a set of result rows. However, OLE-DB differs from ODBC in several ways ….
  • 9. JDBC? Java Database Connectivity: The JDBC standard defines an application program interface (API) that Java programs can use to connect to database servers. The JDBCAPI consists of a set of interfaces and classes written in the Java programming language. JDBC is used in languages that use the JVM. JVM Languages: Java, Kotlin, Scala, Groovy, Clojure, …
  • 12. JDBC in Details • Statement executeQuery()  ResultSet //Query: Select * from Students executeUpdate()  long // NonQuery: Insert – Delete - Create – Update - … • Prepared Statement • Callable Statement
  • 13. SQL Injection! Query: "select * from instructor where name = ’" + name + "’“ User Input: X’ or ’Y’ = ’Y Final Query: select * from instructor where name = ’X’ or ’Y’ = ’Y’ Solution ? • Prepared Statement : select * from instructor where name = ’X’ or ’Y’ = ’Y’ • ?
  • 14. Functions, ProceduresAndTriggers SQL allows the definition of functions, procedures, and methods. Note that databases usually have their own notation for stored procedures/functions! (PL/SQL, T-SQL, PL/pgsql, …) Standard SQL Example (Function):
  • 15. Stored Procedures Standard SQL Example: Calling Stored Procedures: PSM (Persistence Storage Module)?
  • 16. Whole Business logic written in SQL?
  • 17. Triggers? Methods? Will talk about them in more details later! But know that … Also know that some databases support writing methods in them with a programming language. IBM DB2 & Oracle support Java Methods.
  • 18. Back to JDBC • Callable Statement CallableStatement cStmt1 = conn.prepareCall("{? = call some function(?)}"); CallableStatement cStmt2 = conn.prepareCall("{call some procedure(?,?)}"); The data types of function return values and out parameters of procedures must be registered using the method registerOutParameter(), and can be retrieved using get methods similar to those for result sets. See a JDBC manual for more details.
  • 19. Other Features • Metadata Features • Updatable ResultSet • Transactional Features (setAutoCommit()) Read About these features in Database Systems Book by Silberschats , …
  • 20. Embedded SQL We are not going to talk much about embedded SQL since it is not widely used! But in Java we have SQLJ! …
  • 21. Architectural and Design Patterns • Repository Architectural Pattern • DAO • … Related Patterns: • Facade • …
  • 22. Mapping? ORM? ODM? …. • Hibernate, Eclipse Link, OpenJPA, … (Java Persistence API) • Entity Framework, Nhibernate • …
  • 23. Version Control for Database? • MigrationTools • Flyway • Liquibase • ..