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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
package pfe;
import java.util.Calendar;
import java.sql.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class base {
//les valeurs tirer de la base de donnees
int r_client;
int r_user;
int r_trisorie;
String r_nom;
Connection connexion;
Statement instruction1;
PreparedStatement instruction2;
//Nom de mon pilote
String pilote = "com.mysql.jdbc.Driver";
String sql="";
public base(){
try{
//Chargement de mon pilote
Class.forName(pilote);
//Connexion à ma base mysql avec mon login et mot de passe
connexion = DriverManager.getConnection("jdbc:mysql://localhost/base","root","password");
//Création de mon statement qui va me permettre d'executer mes requetes
instruction1 = connexion.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}catch (Exception e1){
System.out.println("echec pilote : "+e1);
}
}
public void afficher() {
String s ="Martin";
try{
/////////////predstatment
String sql = "SELECT * FROM user where nom = ? ";
//String sql = "UPDATE Stocks SET prix = ?, quantite = ? WHERE nom = ?";
//préparation de la requête
PreparedStatement preparedStatement = connexion.prepareStatement(sql);
//on assigne un String au premier paramètre
preparedStatement.setString(1,s);
//exécution de la requête
//preparedStatement.executeQuery();
/////////////predstatment
ResultSet resultat = preparedStatement.executeQuery();//where nom='nouveauNom'
while(resultat.next()){
System.out.println("---------------------------");
System.out.println("Nom : "+resultat.getString("nom"));
System.out.println("Prenom: "+resultat.getString("prenom"));
}
}catch(SQLException e10){System.out.println("erreurrrr "+e10);}
}
////////////////////////////////////////////////////
public void supprimer() {
try{
instruction1.executeUpdate("DELETE FROM user WHERE nom='java'");
}catch(SQLException e11){System.out.println("erreurrrr "+e11);}
}
public void inserer() {
//Calendar Calendar = new Calendar();
Calendar rightNow = Calendar.getInstance();
int i1=rightNow.get(Calendar.YEAR);
int i2=rightNow.get(Calendar.MONTH);
int i3=rightNow.get(Calendar.DAY_OF_MONTH);
int i4=rightNow.get(Calendar.HOUR_OF_DAY);
int i5=rightNow.get(Calendar.MINUTE);
int i6=rightNow.get(Calendar.SECOND);
String a1 = "";
a1= a1.valueOf(i1);
String a2 = "";
a2= a2.valueOf(i2);
String a3 = "";
a3= a3.valueOf(i3);
String a4 = "";
a4= a4.valueOf(i4);
String a5 = "";
a5= a5.valueOf(i5);
String a6 = "";
a6= a6.valueOf(i6);
System.out.println(i1+" "+i2+" "+i3+" "+i4+" "+i5+" "+i6+" ");
String temps = "";
temps= a1.concat(a2).concat(a3).concat(a4).concat(a5).concat(a6);
System.out.println(temps);
try{
instruction1.executeUpdate("INSERT INTO user(nom,prenom) VALUES('javaaaa','dateaaa')");
}catch(SQLException e12){System.out.println("erreurrrr "+e12);}
}
//// mise a jour n'est pasverifier
public void maj(String a, String b){
try{
ResultSet resultat = instruction1.executeQuery("SELECT * FROM user where nom= a and prenom = b");
////resulat.getInt (manquant)// manquant c'est par definition le temps qui reste dans la carte
////rectification du tepms - 5min et
}catch(SQLException e13){System.out.println("erreurrrr "+e13);}
}
public Boolean verifier (String a, String b) {
ResultSet resultat;
Boolean exist = false;
sql = "SELECT * FROM usersys where nom = ? and prenom = ? ";
try{
instruction2 = connexion.prepareStatement(sql);
instruction2.setString(1,a);
instruction2.setString(2,b);
resultat = instruction2.executeQuery();
//if (!resultat.wasNull()){
// exist = true;
//System.out.println("allo allo");
while(resultat.next()){
if (resultat.getString("nom")!= ""){exist=true;}
r_client=resultat.getInt("client");
r_user=resultat.getInt("user");
r_trisorie=resultat.getInt("trisorie");
r_nom=resultat.getString("nom");
//System.out.println(r_client+"\n"+r_user+"\n"+r_trisorie);
}
//}
}catch(SQLException e10){System.out.println("erreurrrr "+e10);}
return(exist);
}
public void inserer_user(String l,String p,int c,int u,int t){
ResultSet resultat;
sql = "INSERT INTO usersys (nom, prenom, client, user, trisorie) VALUES(?,?,?,?,?)";
try{
instruction2 = connexion.prepareStatement(sql);
instruction2.setString(1,l);
instruction2.setString(2,p);
instruction2.setInt(3,c);
instruction2.setInt(4,u);
instruction2.setInt(5,t);
instruction2.executeUpdate();
System.out.println("insertion est effectuer");
}catch(SQLException e10){System.out.println("insertion n,est pas effectuer"+e10);}
}
///methode insertion client
public void inserer_client(String l,String p,int c){
ResultSet resultat;
sql = "INSERT INTO user (nom, prenom, tepmsrest) VALUES(?,?,?)";
try{
instruction2 = connexion.prepareStatement(sql);
instruction2.setString(1,l);
instruction2.setString(2,p);
instruction2.setInt(3,c);
instruction2.executeUpdate();
System.out.println("insertion est effectuer");
}catch(SQLException e10){System.out.println("insertion n,est pas effectuer"+e10);}
}
///fin methode insertion client
} |
Partager