| Retour | Home | Contact |
|---|
Java DataBase Connectivity.
L'ensemble de ces interfaces JDBC est implémenté par les éditeurs sous forme de pilotes (drivers), classés selons 4 catégories :
| Client | Application | |||||
|---|---|---|---|---|---|---|
| API standard | J2C | |||||
| JDBC Connector | ||||||
| JDBC | ||||||
| Pilote JDBC | Type 1 | Type 2 (Java) | Type 3 (Java) | Type 4 (Java) | ||
| Infrastructure | ODBC (natif) | Pilote client SGBDR (natif) | ||||
| Pilote ODBC (natif) | ||||||
| Protocole | SGBDR | SGBDR | Pilote (généralement réseau, comme HTTP, etc.) | SGBDR | ||
| Serveur | SGBDR | SGBDR | Serveur pilote | SGBDR | ||
| Pilote type 2 | Pilote type 4 | |||||
| SGBDR A | SGBDR B | |||||
JDBC est une API de J2SE comprenant :
Le coeur de l'API de JDBC est intégrée à J2SE depuis J2SE 1.1. Son extension est requise par J2EE.
| JDBC | Version | 1 | 2 | 3 | Commentaire | |||||
|---|---|---|---|---|---|---|---|---|---|---|
| Partie | Technologie | Release | 0 | 1 | 2 | 0 | 1 | 0 | ||
| Plate-forme | J2SE | 1.1 | 1.2 | 1.3 | 1.4 | Plate-forme Java intégrante | ||||
| Core | DriverManager | Oui | Coeur obligatoire | |||||||
| Connection | Oui | Connexion | ||||||||
| Statement | Oui | Requête | ||||||||
| getGeneratedKeys | Non | Oui | Clés auto-générées | |||||||
| getMoreResults | Non | Oui | ||||||||
| getConnection | Non | Oui | ||||||||
| Batch updates | Non | Optionnel | Ajoute une requête SQL pour executeBatch | |||||||
| resultSetType | Non | Oui | En avant seulement, en avant/arrière, et isolé ou non | |||||||
| resultSetConcurrency | Non | Oui | Modifiable ou en lecture seule | |||||||
| fetchDirection | Non | Oui | ||||||||
| fetchSize | Non | Oui | Nombre de lignes pour une page | |||||||
| PreparedStatement | Oui | Requête précompilée (SQL dynamique) | ||||||||
| CallableStatement | Oui | Procédure stockée | ||||||||
| ResultSet | ARRAY | Non | getArray | java.sql.Array | ||||||
| Non | updateArray | |||||||||
| TINYINT | getByte | |||||||||
| SMALLINT | getShort | |||||||||
| SMALLINT | getInt | |||||||||
| BIGINT | getLong | |||||||||
| REAL | getFloat | |||||||||
| FLOAT | getDouble | |||||||||
| DOUBLE | ||||||||||
| DECIMAL | getBigDecimal | java.math.BigDecimal | ||||||||
| NUMERIC | ||||||||||
| BIT | getBoolean | |||||||||
| VARCHAR | getString | |||||||||
| CHAR | ||||||||||
| VARBINARY | getBytes | byte[] | ||||||||
| BINARY | ||||||||||
| DATE | Non | getDate | java.sql.Date | |||||||
| TIME | Non | getTime | java.sql.Time | |||||||
| TIMESTAMP | Non | getTimeStamp | java.sql.TimeStamp | |||||||
| LONGVARCHAR | getAsciiStream | Retourne un java.io.InputStream pour un | ||||||||
| getUnicodeStream | Retourne un java.io.InputStream pour un | |||||||||
| LONGVARBINARY | getBinaryStream | Retourne un java.io.InputStream pour un | ||||||||
| Tous | getObject | Le type SQL est retourné comme un java.lang.Objet | ||||||||
| Indice de ligne | Non | getRow | Numéro de ligne courant | |||||||
| Type structuré | Non | getRef | Référence sur un type structuré (object) SQL3. Peut être lazy | |||||||
| Non | updateRef | |||||||||
| BLOB | Non | updateBlob | Binary Large Object | |||||||
| CLOB | Non | updateClob | Binary Character Object | |||||||
| URL | Non | getURL | ||||||||
| Extension | DataSource | Non | Oui | Optionnel | ||||||
| ConnectionEvent | Non | Oui | ||||||||
| RowSet | Non | Oui | ||||||||
Des exemples de pilotes JDBC sont :
Un exemple de code JDBC en environnement J2EE est :
Context namingContext = new InitialContext();
DataSource dataSource = (DataSource) namingContext.lookup
("java:comp/env/jdbc/MyDataSource");
Connection dataSourceConnection = dataSource.getConnection();
try {
PreparedStatement selectStatement = connection.prepareStatement
("SELECT ID, SHORT_NAME, RELATIONSHIPS.TYPE
FROM SKILL, RELATIONSHIPS WHERE ID=RELATIONSHIPS.ID_TO AND RELATIONSHIPS.ID_FROM=?");
selectStatement.setInt (1, 123);
selectStatement.setString (2, "UnType");
ResultSet skillSet = selectStatement.executeQuery();
List linkedSkills = new ArrayList();
while (skillSet.next()) {
int id =
skillSet.getInt ("ID");
String shortName = skillSet.getString ("SHORT_NAME");
Skill newSkill = new
SkillImpl (id, shortName);
linkedSkills.add (newSkill);
}
return linkedSkills;
}
finally {
connection.close(); // Ferme le statement
et le ResultSet
}
| Retour | Home | Contact |
|---|