













































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














































CSCI 4560
Embedded SQL
OCCI
JDBC
Dept. of Computer Science Middle Tennessee State University
Based on the slides coming with the textbook
CSCI 4560
Embedded SQL
OCCI
JDBC
CSCI 4560
Embedded SQL
OCCI
JDBC
To access a database from an application program (as opposed to interactive interfaces)
A majority of database operations are made thru application programs (increasingly thru web applications)
CSCI 4560
Embedded SQL
OCCI
JDBC
Database commands are embedded in a general-purpose programming language
Available to the host language for database calls; known as an API (Application Program Interface)
Minimizes impedance mismatch
CSCI 4560
Embedded SQL
OCCI
JDBC
CSCI 4560
Embedded SQL
OCCI
JDBC
CSCI 4560
Embedded SQL
OCCI
JDBC
Syntax may vary with language
Shared variables (used in both languages) usually prefixed with a colon (:) in SQL
CSCI 4560
Embedded SQL
OCCI
JDBC
int loop; EXEC SQL BEGIN DECLARE SECTION; varchar dname[16], fname[16], ...; char ssn[10], bdate[11], ...; int dno, dnumber, SQLCODE, ...; EXEC SQL END DECLARE SECTION;
CSCI 4560
Embedded SQL
OCCI
JDBC
CONNECT TO server-name AS connection-name AUTHORIZATION user-account-info;
Disconnection: DISCONNECT connection-name;
CSCI 4560
Embedded SQL
OCCI
JDBC
select FNAME, LNAME, ADDRESS, SALARY into :fname, :lname, :address, :salary from EMPLOYEE where SSN == :ssn; if (SQLCODE == 0) printf(fname, ...); else printf(“SSN does not exist: ”, ssn); END-EXEC
SQLCODE holds the value returned after the most recently attempted SQL operation
INTO clause: specifies the program variables into which attribute values from the database are retrieved.
CSCI 4560
Embedded SQL
OCCI
JDBC
select Dnumber into :dnumber from DEPARTMENT where Dname = :dname; EXEC SQL DECLARE EMP CURSOR FOR select Ssn, Fname, Minit, Lname, Salary from EMPLOYEE where Dno = :dnumber FOR UPDATE OF Salary; EXEC SQL OPEN EMP; EXEC SQL FETCH from EMP into :ssn, :fname, :minit, :lname, :salary; while ( SQLCODE == 0 ) { printf("Employee name is: ", Fname, Minit, Lname); prompt("Enter the raise amount: ", raise); EXEC SQL UPDATE EMPLOYEE set Salary = Salary + :raise where CURRENT OF EMP; EXEC SQL FETCH from EMP into :ssn, :fname, :minit, :lname, :salary; }
EXEC SQL CLOSE EMP;
CSCI 4560
Embedded SQL
OCCI
JDBC
Composing and executing new (not previously compiled) SQL statements at run-time a program accepts SQL statements from the keyboard at run-time a point-and-click operation translates to certain SQL query
Composing and executing new (not previously compiled) SQL statements at run-time because the type and number of retrieved attributes are unknown at compile time
CSCI 4560
Embedded SQL
OCCI
JDBC
CSCI 4560
Embedded SQL
OCCI
JDBC