Hello ,
please can any one help me for my this i don't know why didn't gave me my return true he juste return this :les magasins situés dans la ville projetd314.List eMagasin@a401c2
why see my code
thanks
please can any one help me for my this i don't know why didn't gave me my return true he juste return this :les magasins situés dans la ville projetd314.List eMagasin@a401c2
why see my code
Code:
public interface IMagasin {
public double getLatitude();
public double getLongitude();
public String getCode();
public String getVille();
public void setLatitude(double l);
public void setLongitude(double lon);
public void setCode(String string);
public void setVille(String string);
}
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetd314;
import java.sql.*;
import java.sql.PreparedStatement;
import java.lang.Math.*;
import java.util.Vector;
public class Magasin {
static java.sql.Connection c=null;
double latitude=0;
double longitude=0;
String codeville="";
String ville="";
public double getLatitude(){
return latitude;
}
public double getLongitude(){
return longitude;
}
public String getCode(){
return codeville;
}
public String getVille(){
return ville;
}
public void setLatitude(double l){
latitude=l;
}
public void setLongitude(double lon){
longitude=lon;
}
public void setCode(String string){
codeville=string;
}
public void setVille(String string){
ville=string;
}
}
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetd314;
import projetd314.IMagasin;
import projetd314.ListeMagasin;
import projetd314.ListeMagasinAdapter;
import projetd314.Magasin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
public class MagasinServices {
public ListeMagasin listeMagasin=new ListeMagasin();
static java.sql.Connection c=null;
public static void etablirConnexion(){
String pilote="com.mysql.jdbc.Driver";
try{Class.forName(pilote).newInstance();}
catch(Exception e){System.out.println("echec pilote :"+e);
}
String url="jdbc:mysql://localhost:3306/boutiquegeographique";String user="root";String password="";
try{c=DriverManager.getConnection(url,user,password);
}
catch(SQLException e){System.out.println("echec connection a la bdd :"+e);}
}
public ListeMagasin listMagasinsVille(String nomville)
{
double latitude;
double l;
if(Magasin.c==null) etablirConnexion();
try{
PreparedStatement st=c.prepareStatement("select latitude,longitude,nomville from liste_magasins where nomville=?");
st.setString(1, nomville);
ResultSet rs=st.executeQuery();
while(rs.next())
{
Magasin m=new Magasin();
m.setLatitude(rs.getDouble("latitude"));
m.setLongitude(rs.getDouble("longitude"));
m.setVille(rs.getString("nomville"));
listeMagasin.addMagasin(m);
}
}catch(Exception e){System.out.println("erreur selection"+e);}
return listeMagasin;
}
}
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetd314;
import java.util.Vector;
/**
*
* @author kamar
*/
public class ListeMagasinAdapter {
public IMagasin[] liste;
public ListeMagasinAdapter(ListeMagasin obj){
Vector<IMagasin> l=obj.getListe();
liste =l.toArray(new IMagasin[l.size()]);
}
public IMagasin[] getListe(){
return liste;
}
public void setListe(IMagasin[] liste){
this.liste=liste;
}
}
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetd314;
import java.util.Iterator;
import java.util.Vector;
public class ListeMagasin {
private Vector liste=new Vector();
public Magasin getMagasin(int i){
return (Magasin)liste.get(i);
}
public Vector getListe(){
return liste;
}
public void setListe(Vector liste){
this.liste=liste;
}
public void addMagasin(Magasin m){
int i;
for(i=0;i<liste.size();i++)
{
liste.add(m);
return;
}
liste.add(m);
}
public String listMagasinsVille(String nomville){
Iterator iterateur=liste.iterator();
String str="";
while(iterateur.hasNext())
{
Magasin ma=(Magasin)iterateur.next();
String v=ma.getVille();
if(nomville==v){
double lat=ma.getLatitude();
double lon=ma.getLongitude();
str+="Latitude:"+lat+"Longitude:"+lon+"\n";}
}
return str;
}
}
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetd314;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
MagasinServices c=new MagasinServices();
System.out.println("les magasins situés dans la ville "+c.listMagasinsVille("Amiens"));
}
}
Comment