Rappels des concepts fondamentaux - smis inria
Rappels des concepts fondamentaux - smis inria
Rappels des concepts fondamentaux - smis inria
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Exemple Embedded SQL<br />
Exemple JDBC<br />
EXEC SQL DECLARE C1 CURSOR FOR<br />
SELECT NumDoc, NomDoc<br />
FROM DOC<br />
WHERE VilleDoc = ‘Versailles’;<br />
import java.sql.*;<br />
...<br />
class JdbcTest {<br />
static String BD_URL = "jdbc:oracle:@nomBDRoute";<br />
main()<br />
{<br />
EXEC SQL BEGIN DECLARE SECTION<br />
char sqlstate[6], NomDoc[21], VilleDoc[31];<br />
int NumDoc;<br />
EXEC SQL END DECLARE SECTION<br />
}<br />
EXEC SQL OPEN C1 ;<br />
while (notEndofResult(sqlstate) {<br />
EXEC SQL FETCH C1 INTO :NumDoc, :NomDoc;<br />
...<br />
}<br />
EXEC SQL CLOSE C1 ;<br />
57<br />
public static void main (String args [])<br />
throws SQLException, ClassNotFoundException, IOException<br />
{<br />
}<br />
}<br />
Class.forName ("oracle.jdbc.OracleDriver");<br />
Connection BDRoute;<br />
BDRoute =DriverManager.getConnection(BD_URL, "MonNom", "MonPass");<br />
Statement Trajet = BDRoute.createStatement ();<br />
ResultSet ResTrajet = Trajet.executeQuery<br />
("SELECT * FROM Route WHERE Depart = ‘Paris’");<br />
while ( ResTrajet.next() )<br />
{ System.out.println (ResTrajet.getString ("Arrivee")); }<br />
ResTrajet.close();<br />
Trajet.close();<br />
BDRoute.close();<br />
58<br />
Exemple : Oracle PL/SQL<br />
Curseurs PL/SQL : exemple<br />
• Procédure Anonyme<br />
Client<br />
PL/SQL<br />
Moteur<br />
PL/SQL<br />
• Procédure stockée (invocation directe)<br />
Client<br />
RPC<br />
Moteur<br />
PL/SQL<br />
• Procédure stockée (invocation indirecte)<br />
Client<br />
Mise à jour SQL<br />
Moteur<br />
PL/SQL<br />
Serveur<br />
SQL<br />
Serveur<br />
SQL<br />
Serveur<br />
SQL<br />
BD<br />
BD<br />
BD<br />
PL/SQL<br />
trigger<br />
PL/SQL<br />
59<br />
DECLARE<br />
CURSOR Compta IS<br />
SELECT nom, salaire FROM Employe WHERE service = ‘comptabilité’;<br />
Emp Compta%ROWTYPE;<br />
BEGIN<br />
OPEN Compta;<br />
FETCH Compta INTO Emp;<br />
WHILE Compta%FOUND LOOP<br />
IF Emp.salaire IS NOT NULL AND Emp.Salaire < 30.000 THEN<br />
UPDATE Employe SET salaire = salaire * 1,05 WHERE nom = Emp.nom<br />
END IF;<br />
FETCH Compta INTO Emp;<br />
END LOOP;<br />
CLOSE C;<br />
END;<br />
60