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
|
public void writeLogDB(String txt) throws SQLException, ClassNotFoundException{
//Configuration SQL
Connection con;
Statement stm;
//Configuration Tables
String tableName = "logMyself";
String table0 = "logDate";
String table1 = "logHour";
String table2 = "logInfo";
//Configuration Colonnes
String loginfo_is = txt;
//Configuration DATE ET HEURE
SimpleDateFormat heures = null;
SimpleDateFormat dates = null;
Date aujourdhui = new Date();
Date aujourdhui1 = new Date();
heures = new SimpleDateFormat("k:mm:ss ");
dates = new SimpleDateFormat("MM/dd/yyyy ");
//LAncement Driver et FIchier
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\MSAccessProject/logMyself.mdb;DriverID=22; READONLY=false");
stm = con.createStatement();
// Création d'une table
if (con.equals(tableName) ){
String addTable = " CREATE TABLE " + tableName + " (" + table0 + " Date" + "," + table1 + " Time" + "," + table2 + " char(255) )";
stm.execute(addTable);
}
// Entrer de valeur
String addRow = "INSERT INTO " + tableName + " VALUES ( #" + dates.format(aujourdhui1) + "#,#" + heures.format(aujourdhui) + "# , '" + loginfo_is + "' )";
stm.execute(addRow);
System.out.println("Info" + " "+ txt);
if (con != null) { con.close(); }
if (stm != null) { stm.close(); }
}
} |
Partager