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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
import java.awt.Frame;
import java.sql.*;
import javax.swing.JOptionPane;
class ThreadJDBC extends Thread implements Runnable
{
String heure_arrivee;
int temps_guichet;
public ThreadJDBC(String heure_arrivee, int temps_guichet){
this.heure_arrivee = heure_arrivee;
this.temps_guichet = temps_guichet;
}
public void run() {
try {
// Connect to the local database
String url = "jdbc:mysql://localhost/test" ;
String login = "root";
String password = "";
Connection conn = DriverManager.getConnection(url,login,password);
// Query the employee names
Statement stmt = conn.createStatement ();
JOptionPane.showMessageDialog(new Frame(),"heure_arrivee:"+heure_arrivee);
JOptionPane.showMessageDialog(new Frame(),"temps_guichet:"+temps_guichet);
JOptionPane.showMessageDialog(new Frame(),"INSERT INTO client (heure_arrivee,temps_guichet) VALUES (\"" + heure_arrivee + "\"," + temps_guichet + ")");
// fonctionne !
//String requete = "CREATE TABLE client (id_client INT NOT NULL AUTO_INCREMENT,heure_arrivee varchar(8) NOT NULL,temps_guichet INT NOT NULL,temps_file INT NOT NULL,PRIMARY KEY(id_client) )";
//String requete = "drop table client";
//String requete = "describe client";
// String requete = "select * from client";
// String requete = "update client set temps_guichet= " + temps_guichet +" where temps_guichet=20";
// marche pas!!
String requete = "INSERT INTO client (heure_arrivee,temps_guichet) VALUES ('22:44:55',3)";
//String requete = "INSERT INTO client (heure_arrivee,temps_guichet) VALUES (\"" + heure_arrivee + "\"," + temps_guichet + ")";
System.out.println(requete);
stmt.execute(requete);
/* ResultSet rset = stmt.executeQuery (requete);
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
rset.close();
*/
stmt.close();
conn.close();
}
catch ( Exception E ) {
JOptionPane.showMessageDialog(new Frame(),"Impossible de se connecter à la base de donnée!");
}
}
} |
Partager