Petit probleme avec mon DataSource
Bonjour,
Je galere avec les jndi voila mon pb:
Mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Context ctx = new InitialContext();
if ( ctx == null ) {
throw new NamingException("Uh oh -- no context!");
}
DataSource ds = (DataSource)
ctx.lookup("java:/comp/env/jdbc/postgres");
if ( ds == null ) {
throw new NamingException("Data source not found!");
}
System.out.println("TOP");
Connection con = ds.getConnection(); // <= erreur ici ????
System.out.println("TOP"); |
Mon fichier web.xml:
Code:
1 2 3 4 5 6 7
|
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref> |
et mon fichier server.xml:
Code:
1 2 3 4 5 6 7 8 9 10
|
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
<Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost/test" username="toto" password="toto"/>
</GlobalNamingResources> |
voila les infos utiles.
Ce que je comprends pas c'est qu'avec un DriversManager tout fonctionne.
Code:
1 2 3 4
|
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost/test?user=toto&password=toto";
Connection con = DriverManager.getConnection(url); |
Je suppose donc un oublie de ma part mais lequel ????
Voila toute les idees sont les bienvenues. :wink: