IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Frameworks Web Java Discussion :

probleme d'affichage des donnèes d'une base avec ejb


Sujet :

Frameworks Web Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    developpeur
    Inscrit en
    Janvier 2012
    Messages
    111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : developpeur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Janvier 2012
    Messages : 111
    Points : 17
    Points
    17
    Par défaut probleme d'affichage des donnèes d'une base avec ejb
    Bonjour je travaille avec eclipse la version ganymede et le serveur jboss 4.2.1 lorsque j'essai j'utiliser les requetes JPQL pour l'affichage des donnèes de ma base j'obtiens ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    entityBeans.Customer@f70f8e
    voici mon customer bean


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    package entityBeans;
     
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import java.io.Serializable;
     
     
    @Entity
    public class Customer implements Serializable {
       private int idcustomer;
       private String firstname;
       private String lastname;
       private String email;
       private String adresse;
       private String zipCode;
       private String city;
       private int phone;
       private String password;
     
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
    public int getIdcustomer() {
    	return idcustomer;
    }
    public void setIdcustomer(int idcustomer) {
    	this.idcustomer = idcustomer;
    }
    public String getFirstname() {
    	return firstname;
    }
    public void setFirstname(String firstname) {
    	this.firstname = firstname;
    }
    public String getLastname() {
    	return lastname;
    }
    public void setLastname(String lastname) {
    	this.lastname = lastname;
    }
    public String getEmail() {
    	return email;
    }
    public void setEmail(String email) {
    	this.email = email;
    }
    public String getAdresse() {
    	return adresse;
    }
    public void setAdresse(String adresse) {
    	this.adresse = adresse;
    }
    public String getZipCode() {
    	return zipCode;
    }
    public void setZipCode(String zipCode) {
    	this.zipCode = zipCode;
    }
    public String getCity() {
    	return city;
    }
    public void setCity(String city) {
    	this.city = city;
    }
    public int getPhone(){
    	return phone;
    }
    public void setPhone(int phone){
    	this.phone=phone;
    }
    public String getPassword(){
    	return password;
    }
    public void setPassword(String password){
    	this.password=password;
    }
     
    }

    interface :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    package sessionBeans;
    import java.util.List;
    import entityBeans.Customer;
    import javax.ejb.Remote;
     
     
    @Remote
    public interface GestionContactRemote {
      public String coucouContact(String nomContact);
      public void addContact(String first, String last, String mail, String add,String zip, String city, int phone,String password);
      //public String findCustomerById(int idcustomer);
      public List<Customer>getCustomer();
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    package sessionBeans;
     
     
     
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
     
    import java.util.List;
    import entityBeans.Customer;
     
    @Stateless(name="GestionContactRemote")
    @Remote(GestionContactRemote.class)
    public class GestionContactBean implements GestionContactRemote{
    	@PersistenceContext
    	EntityManager em;
     
     
    	public String coucouContact(String nomContact) {
     
    		return "Coucou,"+nomContact;
    	}
     
     
     
     
    	public void addContact(String first, String last, String mail, String add,String zip, String city, int phone,String password) {
    		Customer c = new Customer();
    		c.setFirstname(first);
    		c.setLastname(last);
    		c.setEmail(mail);
    		c.setAdresse(add);
    		c.setZipCode(zip);
    		c.setCity(city);
    		c.setPhone(phone);
    		c.setPassword(password);
    		em.persist(c);
     
     
    	}
     
     
     
     
     
    	public List<Customer> getCustomer() {
     
    		return em.createQuery("SELECT c FROM Customer c").getResultList();
     
     
     
    	}
     
     
     
     
    	//public String findCustomerById(int idcustomer) {
    		//Customer c = em.find(Customer.class,idcustomer);
    		//return c.getLastname()+","+c.getFirstname();
    	//}
     
     
     
     
     
     
     
    }

    et la fonction main que j'appele dans l'application cliente:



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import sessionBeans.GestionContactRemote;
    import entityBeans.Customer;
    import java.util.List;
    import java.util.Iterator;
    public class Main {
    	public static void main(String[] args) {
    		try{
    			  Context context = new InitialContext();
    			  GestionContactRemote beanRemote = (GestionContactRemote)context.lookup("GestionContactRemote/remote");
    			  System.out.println(beanRemote.coucouContact("Mon Premier Client EjB3 "));
    			  beanRemote.addContact("jkl","lomp","pom","htyfg","kiluy","lopjg",9,"opli");
    			  System.out.println("Le nom du contact a ètè ajoutè dans la base:");
    			  //+beanRemote.findCustomerById(0)
    			  List<Customer> customers = beanRemote.getCustomer();
    			  for (Iterator<Customer> iter= customers.iterator();iter.hasNext();){
                	  Customer mycust = (Customer)iter.next();
                	  System.out.println(mycust);
                  }
    		}
    		catch(NamingException e){
    			e.printStackTrace();
    		}
    	}
     
    	/* (non-Java-doc)
    	 * @see java.lang.Object#Object()
    	 */
    	public Main() {
    		super();
    	}
     
    }

  2. #2
    Modérateur
    Avatar de paissad
    Homme Profil pro
    Ingénieur de développement (Java/JEE/Eclipse RCP,EMF & webMethods)
    Inscrit en
    Avril 2006
    Messages
    1 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur de développement (Java/JEE/Eclipse RCP,EMF & webMethods)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 043
    Points : 2 560
    Points
    2 560
    Par défaut
    Bonjour,
    dans ta classe Customer, il faut redéfinir la méthode toString();
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public String toString() { .... }
    c'est tout

    Cordialement,
    Nous n'héritons pas de la terre de nos parents, nous l'empruntons à nos enfants.
    Le chat du site est aussi ici pour aider. Ne pas hésiter à visiter !

Discussions similaires

  1. [C#] Affichage des données d'une base de données à travers un Datagrid
    Par Me,Myself and I dans le forum Windows Forms
    Réponses: 3
    Dernier message: 23/02/2007, 16h38
  2. [MySQL] Problème avec affichage des données d'une base MySQL
    Par leclone dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 27/12/2006, 12h40
  3. [Tableaux] affichage des données d'une base
    Par Nickwell dans le forum Langage
    Réponses: 1
    Dernier message: 29/09/2006, 17h14
  4. [MySQL] Affichage des données d'une base
    Par leloup84 dans le forum PHP & Base de données
    Réponses: 30
    Dernier message: 01/02/2006, 16h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo