{filelink=7022}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/*
* Ce programme crée une connexion à la
* Base de données MySql et exécute une requête
* update groupée. si l'une de requête d'insertion
* échoue, le programme annule l'exécution de tous
* les restes.
*
*/
public class BatchUp
{
public static void main(String[] args) throws Exception
{
Connection conn=null;
try
{
// Ouvrir une connexion à la Base de données 'Cours'
conn = DriverManager.getConnection("jdbc:mysql://localhost/cours", "root", "");
conn.setAutoCommit(false); // Désactiver le mode AutoCommit
Statement stmt = conn.createStatement();
// Créer un lot de requête d'insertion
stmt.addBatch("INSERT INTO Test (id, nom, prix) VALUE (0, 'Sakoba test', '1500€')");
stmt.addBatch("INSERT INTO Test (id, nom, prix) VALUE (0, 'Steve Jhon', '2500€')");
stmt.addBatch("INSERT INTO Test (id, nom, prix) VALUE (0, 'NiColas Salo', '100€')");
// Exécuter le lot
int[] resultats = stmt.executeBatch();
conn.commit();
} catch (SQLException ex)
{
// En cas d'erreur, annuler
conn.rollback();
ex.printStackTrace();
} finally {
if (conn!= null) {
conn.close();
}
}
}
}
A Voir sur le même Sujet:
- extraire bdd batch exemple
- créer batch to update java flash
- update
- creation de batch wordpress
- java.mesexemples.com+transaction-creation-dun-batch-update-pour-executer-une-mise-a-jour-de-masse
- autocommit
- créer un lot + java
- bat 3 24 av java masse
- batch java excel to sql
- batch d'une transaction sql