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 |
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 |
CODE |
org.objectweb.jonas.service.ServiceException : DatabaseService: Cannot create datasource: jdbc_allobiz, java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlXADataSource |
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 |
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 |
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(); } ... |
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) |
CODE |
javax.sql.DataSource ds = (javax.sql.DataSource)context_.lookup(dbName); |
Bon Gfx, arrête de faire le pitre avec Sir, merde!
Problème résolu...
En remplaçant
CODE |
String dbName = "java:comp/env/jdbc/jdbc_mabase"; |
CODE |
String dbName = "jdbc_mabase"; |
La puissance du Gfx catalysé par le Sir Concis : même plus besoin de répondre aux problèmes, ils se résolvent par eux même.
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)