Biblioteca Java - Rev 28
Subversion Repositories:
/*
* BatchUpdate.java
*/
package lab.scd.db.jdb20;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import lab.scd.db.util.DBConfig;
/**
* Class created by @author Mihai HULEA at Mar 13, 2005.
*
* This class is part of the laborator4_db project.
*
* JDBC 2.0 a introdus posibilitatea de a trimite catre baza de date un set de mai
* multe updateuri ca un set. Acest procedeu este mult mai eficient decat trimiterea
* fiecarei comenzi de update separat.
*/
public class BatchUpdate {
public static void main(String[] args) {
try{
// incarcare driver petru baza de date
Class.forName("com.mysql.jdbc.Driver");
//conectare la baza de date
Connection con = DriverManager.getConnection("jdbc:mysql://"+DBConfig.HOST+"/"+DBConfig.DATABASE+"?user="+DBConfig.USER+"&password="+DBConfig.PWD);
System.out.println("Conexiune la baza de date realizata.");
//start tranzactie
con.setAutoCommit(false);
try{
Statement stmt = con.createStatement();
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Amaretto1', 9898)");
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Hazelnut1', 900)");
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Amaretto_decaf', 77)");
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Bygtoac1', 69)");
int [] updateCounts = stmt.executeBatch();
}catch(Exception e){
e.printStackTrace();
//rollback transaction in caz de eroare in cadrul uneia dintre operatiile de ipdate
con.rollback();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
* BatchUpdate.java
*/
package lab.scd.db.jdb20;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import lab.scd.db.util.DBConfig;
/**
* Class created by @author Mihai HULEA at Mar 13, 2005.
*
* This class is part of the laborator4_db project.
*
* JDBC 2.0 a introdus posibilitatea de a trimite catre baza de date un set de mai
* multe updateuri ca un set. Acest procedeu este mult mai eficient decat trimiterea
* fiecarei comenzi de update separat.
*/
public class BatchUpdate {
public static void main(String[] args) {
try{
// incarcare driver petru baza de date
Class.forName("com.mysql.jdbc.Driver");
//conectare la baza de date
Connection con = DriverManager.getConnection("jdbc:mysql://"+DBConfig.HOST+"/"+DBConfig.DATABASE+"?user="+DBConfig.USER+"&password="+DBConfig.PWD);
System.out.println("Conexiune la baza de date realizata.");
//start tranzactie
con.setAutoCommit(false);
try{
Statement stmt = con.createStatement();
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Amaretto1', 9898)");
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Hazelnut1', 900)");
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Amaretto_decaf', 77)");
stmt.addBatch("INSERT INTO STOC " +
"VALUES('Bygtoac1', 69)");
int [] updateCounts = stmt.executeBatch();
}catch(Exception e){
e.printStackTrace();
//rollback transaction in caz de eroare in cadrul uneia dintre operatiile de ipdate
con.rollback();
}
}catch(Exception e){
e.printStackTrace();
}
}
}