1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| package acces_concurrents;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/**
* <p>se connecte à sqlite et écrit un nombre et son carré comme unique enregistrement
* de la base "nombres"</p>
* @author lolveley
*
*/
public class Gene_1 extends Thread {
@Override
public void run() {
Statement stmt = null;
Connection con = null;
try {
// sqlite driver
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:genants.db");
con.setAutoCommit(false);
stmt = con.createStatement();
stmt.execute("drop table if exists GENANTS;");
stmt.execute("create table GENANTS (n int,n2 int);");
stmt.executeUpdate("insert into GENANTS values (1,1);");
stmt.executeUpdate("update GENANTS set n=2 where n=1;");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stmt.executeUpdate("update GENANTS set n2=2 where n=2;");
con.commit();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
Partager