Accueil > Forum > > > > EJB STATFULL
EJB STATFULL
jeudi 2 septembre 2010 à 16:59:06 |
EJB STATFULL

aya2007
|
Salut a tous
Je me suis bloqué avec mon EJB statefull qui traite une table Entreprise
Code Java :
package beanStatFul;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@Stateful(name="Entreprise")
public class EntrepriseBean implements Entreprise {
//Partie Declaration des attributs
private String nomination;
private String nomResponsable;
private String adresse;
private String dateCreation;
private int nombreEmployee;
private String activitePrincipale;
private java.sql.Connection con = null;
private java.sql.Statement stmt = null;
/*
* *Constructeur
*/
@PostConstruct
public void initialise() {
nomination = "";
nomResponsable = "";
adresse = "";
dateCreation = "";
activitePrincipale = "";
nombreEmployee = 0;
}
public EntrepriseBean()
{
/*methode initialisant la connexion a la base de données
Chargement du pilote
*/
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception e) {
e.printStackTrace();
System.exit(99);
}
// Connexion à la base de données MySQL "mtpbdd"
try {
String DBurl = "jdbc:mysql://localhost:3306/mtpbdd";
con = DriverManager.getConnection(DBurl,"root","");
stmt = con.createStatement();
} catch (SQLException e) {
System.out.println("erreur de connexion");
e.printStackTrace();
}
}
//Accesseurs et mutateurs
public String getNomination() {
return nomination;
}
public void setNomination(String nomination) {
this.nomination = nomination;
}
public String getNomResponsable() {
return nomResponsable;
}
public void setNomResponsable(String nomResponsable) {
this.nomResponsable = nomResponsable;
}
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
public String getDateCreation() {
return dateCreation;
}
public void setDateCreation(String dateCreation) {
this.dateCreation = dateCreation;
}
public int getNombreEmployee() {
return nombreEmployee;
}
public void setNombreEmployee(int nombreEmployee) {
this.nombreEmployee = nombreEmployee;
}
public String getActivitePrincipale() {
return activitePrincipale;
}
public void setActivitePrincipale(String activitePrincipale) {
this.activitePrincipale = activitePrincipale;
}
/*Mise a jour d'une ligne de la table
*/
public boolean updateEntreprise (){
boolean var=false;
try{
String requete = "UPDATE Entreprise SET Nomination='"+this.nomination+"' " +
"and NomResponsable='"+this.nomResponsable+"' and Adresse='"+this.adresse+"'and" +
" dateCreation='"+this.dateCreation+"'and ActivitePrincipale='"+this.activitePrincipale+"'" +
" and Nombremployee='"+this.nombreEmployee+"'";
var=true;
}
catch (Exception e) {
System.out.println("Erreur pendant la suppression");
}
return var;
}
/*Insertion ligne dans la table
* */
public int insertEntreprise(){
ResultSet resultats = null;
int idGenere = -1;
try {
stmt.executeUpdate("INSERT INTO Entreprise (Nomination,NomResponsable,Adresse,DateCreation" +
",NombreEmployee,activitePrincipale) values('"+this.getNomination()+"'," +
" '"+ this.getNomResponsable()+"', '"+this.getAdresse()+"', '"+ this.getDateCreation()+
"','"+this.getNombreEmployee()+"','"+this.getActivitePrincipale()+"')",Statement.RETURN_GENERATED_KEYS);
resultats = stmt.getGeneratedKeys();
if (resultats.next()) {
idGenere = resultats.getInt(1);
}
resultats.close();
} catch (SQLException e) {
e.printStackTrace();
}
return idGenere;
}
/*suppression d'une ligne de la table
*/
public Boolean deleteEntreprise(){
Boolean var=false;
try {
stmt.executeUpdate("Delete From Entreprise Where Nomination='"+this.nomination+"' " +
"and NomResponsable='"+this.nomResponsable+"' and Adresse='"+this.adresse+"'and" +
" dateCreation='"+this.dateCreation+"'and Nombremployee='"+this.nombreEmployee+"'");
var=true;
} catch (SQLException e) {
e.printStackTrace();
}
return var;
}
/* Affichage d'une ligne
* @see statefullBean.Entreprise#loadEntreprise(int)
*/
public void loadEntreprise (int key){
ResultSet resultats = null;
try {
boolean encore = false;
resultats = stmt.executeQuery("Select Nomination, NomResponsable,Adresse,DateCreation," +
"NombreEmployee,activitePrincipale from Entreprise Where Nomination="+key);
if (resultats != null)
encore = resultats.next();
if (encore)
{
this.setNomination(resultats.getString(1)) ;
this.setNomResponsable(resultats.getString(2));
this.setAdresse(resultats.getString(3));
this.setDateCreation(resultats.getString(4));
this.setNombreEmployee(resultats.getInt(5));
this.setActivitePrincipale(resultats.getString(6));
}
else
System.out.println ("Il n'y a aucun enregistrement avec cet paramètre !");
resultats.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
//
/* Affichage de toutes les ligne
* @see statefullBean.Entreprise#loadEntreprise(int)
*/
public void getAllEntreprise (){
ResultSet resultats = null;
try {
resultats = stmt.executeQuery("Select Nomination, NomResponsable,Adresse,DateCreation," +
"NombreEmployee,activitePrincipale from Entreprise");
boolean encore = resultats.next();
while (encore) {
this.setNomination(resultats.getString(1)) ;
this.setNomResponsable(resultats.getString(2));
this.setAdresse(resultats.getString(3));
this.setDateCreation(resultats.getString(4));
this.setNombreEmployee(resultats.getInt(5));
this.setActivitePrincipale(resultats.getString(6));
encore = resultats.next();
}
resultats.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
j'ai une interface remote et une classe de test
Code : args)
{
Properties props = System.getProperties();
Context ctx;
Entreprise TestEntreprise= null;
try {
ctx = new InitialContext(props);
TestEntreprise = (Entreprise) ctx.lookup("EntrepriseBean/remote");
} catch (NamingException e4) {
// TODO Auto-generated catch block
e4.printStackTrace();
}
TestEntreprise.insertEntreprise();
}
}
J'ai un message d'erreur suivant :
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at beanManaged.Entrepriseaction.main(Entrepriseaction.java:29)
Exception in thread "main" java.lang.NullPointerException
at beanManaged.Entrepriseaction.main(Entrepriseaction.java:34)
|
|
jeudi 2 septembre 2010 à 18:34:50 |
Re : EJB STATFULL

super_toinou
|
Hello,
c'est ton client qui est incapable d'appeler le serveur.
Soit tu mets tout ce qu'il faut dans les variables d'environnement.
Soit tu mets (et c'est plus la norme) un fichier jndi.properties dans ton classpath contenant au moins les infos suivantes:
java.naming.factory.initial=la factory pour ton serveur
java.naming.factory.url.pkgs=les urls de packages pour ton serveur
java.naming.provider.url=host:port
et après tu fais
Context ctx = new InitialContext();
pour les propriétés du fichier jndi.properties, cherche sur le net des s exemples en fonction de ton serveur d'app
++
|
|
vendredi 3 septembre 2010 à 00:40:08 |
Re : EJB STATFULL

aya2007
|
Merçi pour ta réponse
J'ai esséyé avec la 2emme solution que tu m'a proposé
voila mon fichier jndi.properties Code Java :
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
le problem est le suivant :
quand je sauvegarde ce fichier dans la racine il affiche toujour la meme erreur precedente et si je le sauvegarde dans la racine src
j'ai cette erreur Code Java : log4j:[b]WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
log4j:WARN Please initialize the log4j system properly.
javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at beanManaged.Entrepriseaction.main(Entrepriseaction.java:32)
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1385)
... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:243)
... 5 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:239)
... 5 more
Exception in thread "main" java.lang.NullPointerException
at beanManaged.Entrepriseaction.main(Entrepriseaction.java:37)[/b]
Samia BENABI
|
|
vendredi 3 septembre 2010 à 10:55:22 |
Re : EJB STATFULL

super_toinou
|
Hello,
si t'es sur JBoss regardes ce tutorial :
http://www.eclipsetotale.com/articles/Introduction_EJB3_avec_Eclipse.html
Ca prend 15 min et c'est super bien expliqué.
|
|
vendredi 3 septembre 2010 à 15:38:49 |
Re : EJB STATFULL

aya2007
|
Merçi beaucoup je vais ésséyer avec jboss car j'utilise tomcat
je veux savoir maitenant comment faire le lien entre mon ejb statefull et un formulaire JSF qui fait le traitement d'une table des entreprises "affichage ajout suppression.." es ce que je declare ma classe de test EJB comme manager bean ??
Samia BENABI
|
|
Cette discussion est classée dans : public, string, resultats, nomination, nomresponsable
Répondre à ce message
Sujets en rapport avec ce message
Serveur multiple qui redistribue les données à TOUT ses clients... [ par Hellway ]
Voilà, mon problème est assez compliqué et je n'ai trouvé en aucun endroit de la toile réponse à ma question. Je tente donc le coup ici.Je bosse actue
recuperer contenu de balise xml avec sax [ par lolofx ]
salut, voila, je voudrais recuprer le contenu d'une balise xml choisi voila la sourcepour info nom correspond au nom de la balisefichier au nom du fic
java, aidez moi je craque :'( [ par yasminexp ]
slt voila ja deux fichier un Livre.java qui creer des livre avec nom auteur nbpage ... dedans un fonction compare2 qui est apler dans TestLivre.java,
précision exo java sur implémentation [ par so250581 ]
Bonjour, j'ai réalisé un sujet d'exercice sur les implémentations en java. J'ai mis les réponses que je pensais mais je n'en suis pas du tout sûr. Pou
JUnit - "java.lang.StackOverflowError" au lancement de la classe de test dans Eclipse [ par biboune56 ]
Bonjour à tous,Me formant aux tests unitaires, j'ai écrit 2 classes :la 1re classe (pour le test) : ----------------------------------import junit.fra
filtre [ par sheorogath ]
slt tout le monde monde voila mon prob:j'ai creer un programme qui lit la premiere ligne d'un fichier avec un certaine extension mais je voudrais que
applet print [ par neo1260 ]
Salut, c encore moi avec mon probléme d'applet, j'ai laissé tombé la classe interne mais il me met une erreude compilation au niveau du book.append (p
Communication entre 2 classes [ par cpraud ]
Bonjour je cherche à faire communiquer 2 classesla 1ere extends Appletla 2ième extends la 1ere, et doit me renvoyer un paramètre de la page HTMLmais j
de l'aide pour Vector [ par tocotodo ]
Bonjour je une class Radio.java et autre TestRadio.pour mon vector , toutes champs d'information donc brandName, model , option et prix, je les optien
passer de fichier texte a des classes java [ par anneli ]
alo,je travaille avec des fichiers textes contenant des données sous la forme suivante:class Voiture extends class java.lang.Object{ public stat
Livres en rapport
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
J2EEJ2EE par barhoum1111
Cliquez pour lire la suite par barhoum1111
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|