IPB

Bienvenue invité ( Connexion | Inscription )

[ En ligne ] · Standard · Linéaire+

> [jndi-jonas] Mysql Connexion, problème, ça marche pas.

PoP
post 06/04/2004 12:32
Message #1


ragondin interstellaire
*****

Groupe : Membres
Messages : 3,059
Inscrit le : 16/05/2002 23:00
Lieu : DTC, au fond à gauche
Membre no. 8



Glop,

J'ai de nouveau un problème qui ne fait d'augmenter mon risque de devenir chauve avant l'heure.
Dans le cadre d'une application web, je dois me connecter à une base de données en utilisant JNDI.
Mon environnement est le suivant:
CODE
serveur d'appli : JOnAS 3.2
serveur bdd : mySql 4.0.17-standard
driver jdbc : org.gjt.mm.mysql.Driver


J'ai installé MySQL Connector/J version 3.0.11-stable dans /opt/jonas/lib/ext. Sous jonasAdmin dans la partie ressources/databases, j'essaye d'ajouter une DataSource avec les paramètres suivants:
CODE
name : jdbc_mabase
jndi name : jdbc_mabase
url : jdbc:mysql://localhost/mabase
jdbc driver : org.gjt.mm.mysql.Driver
username : monlogin
userpassword : monpassword
factory : com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
mapper : rdb.mysql
maximum age : 30
checking level : 1
test : SELECT 1
pool minimum : 0
pool maximum : -1


Or, quand je clique sur Apply/Confirm j'ai droit à:
CODE
org.objectweb.jonas.service.ServiceException : DatabaseService: Cannot create datasource:
jdbc_allobiz, java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlXADataSource


Youpi kay...petit tour sur Google où j'apprends que:
QUOTE
MysqlXADatasource was pulled due to licensing conflicts, and the fact that it didn't really work all that well. The documentation snafu is an oversight on my part smile.gif


Sachant que JOnAS me demande une "Name of the class implementing the XAPoolDataSource" pour la Factory, je fais comment?

Quelqu'un a-t-il déjà été confronté à ce problème? Comment se connecter à une base de données mySQL avec JNDI?

EDIT
Bon, finalement j'ai mis le champ Factory à "none". Désormais j'obtiens ça quand je déploie la DataSource:
CODE

The JOnAS Server 'jonas' version 3.2 is ready
2004-04-06 14:30:43,902 : Server.start : Jonas server jonas started on  rmi/jrmp
[root@dudulle ext]# 2004-04-06 14:31:01,523 : DataBaseServiceImpl.createDataSource : Mapping ConnectionManager jdbc:mysql://localhost/mabase on jdbc_mabase


Dans le code de ma servlet, j'ai mis ceci dans le init():
CODE

 public void init(ServletConfig config) throws ServletException {
   // Servlet config initialization
   super.init(config);
   // @mpo @tlg - Ref OST DE-2004-00001 poste 1 - passage à jndi
     System.out.println("# JNDI # Step 1");
try{
       Hashtable env = new Hashtable();
     String dbName = "java:comp/env/jdbc/jdbc_mabase";
     InitialContext context_ = new InitialContext();
     System.out.println("# JNDI # Step 2");
     javax.sql.DataSource ds = (javax.sql.DataSource)context_.lookup(dbName);
     System.out.println("# JNDI # Step 3");

     java.sql.Connection conn = ds.getConnection();
     try {
       String sql = "SELECT nom, prenom FROM utilisateurs";
       java.sql.Statement stmt = conn.createStatement();
       java.sql.ResultSet rs = stmt.executeQuery(sql);
       while (rs.next()) {
         System.out.println("joyeux drille: " + rs.getString("prenom") + " " + rs.getString("nom"));
       }
       rs.close();
       stmt.close();
     }
     finally {
       conn.close();
     }
 } catch (Exception e) {
   e.printStackTrace();
 }
...


Et, quand j'appelle ma servlet, j'ai droit à ça:
CODE

# JNDI # Step 1
# JNDI # Step 2
2004-04-06 14:32:29,972 : NamingManager.getComponentContext : There is no component context.
java.lang.Exception: Stack trace
       at java.lang.Thread.dumpStack(Thread.java:1071)
       at org.objectweb.jonas.naming.NamingManager.getComponentContext(NamingManager.java:208)
       at org.objectweb.jonas.naming.java.javaURLContext.findContext(javaURLContext.java:149)
       at org.objectweb.jonas.naming.java.javaURLContext.lookup(javaURLContext.java:176)
       at javax.naming.InitialContext.lookup(InitialContext.java:347)
       at monappli.bidule.truc.chose.MaServlet.init(MaServlet.java:200)


Or, à la ligne 200 j'ai
CODE
javax.sql.DataSource ds = (javax.sql.DataSource)context_.lookup(dbName);


Qu'est-ce que j'ai mal fait? Dois-je ajouter quelque-chose dans le web.xml de ma webapp?



--------------------
PoP
"Consommez malin, consommez du ragondin!"
user posted image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic


Reply to this topicTopic OptionsStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :
 

Version bas débit Nous sommes le : : 24/05/2024 20:45