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
| COLOR="Blue"]package BD;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Date;
public class ServiceVol {
public String VilleDepart;
public String VilleArrivee;
public String DateLimit;
String v=new String();
public String getvilleDepart(){return this.VilleDepart;}
public void setvilleDepart(String villeDepart){this.VilleDepart=villeDepart;}
public String getvilleArrivée(){return this.VilleArrivee;}
public void setvilleArrivée(String villeArrivée){this.VilleArrivee=villeArrivée;}
public String getDateLimit(){return this.DateLimit;}
public void setDateLimit(String DateLimit){this.DateLimit=DateLimit;}
public String requete (String villedepart,String villearivee,String datelimit){
//connection base de donnee
try{
String pilote = "com.mysql.jdbc.Driver";
try {
Class.forName(pilote);
Connection connexion = DriverManager.getConnection("jdbc:mysql://localhost/maBD","root","pass");
Statement instruction = connexion.createStatement();
ResultSet r=instruction.executeQuery( "SELECT * FROM vols WHERE v_depart = \""+VilleDepart+"\"AND v_arrivee = \""+VilleArrivee+"AND date_depart=\""+DateLimit+"");
while( (r.next())){
v.concat(r.getString("num_vol"));
v.concat( r.getString("v_depart"));
v.concat(r.getString("v_arrivee"));
v.concat(r.getDate("date_depart").toString());
}
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return v ;
}
}[/COLOR] |
Partager