Tomcat 5.5.9 Connection Pool / JNDI / DBCP

2005-04-20 Thread Lars Nielsen Lind
Hi.
I have some problems with Tomcat 5.5.9 Connection Pooling / JNDI / DBCP
When running my java component (se below) I receive this NamingException:
/NE: 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/

If I add this code:
System.setProperty("java.naming.factory.initial",  
"org.apache.naming.java.javaURLContextFactory");
System.setProperty("java.naming.factory.pkgs",  "org.apache.naming");

to the constructor in the java component, I receive this exception:
/NE: Name java: is not bound in this Context/
What is wrong and what is the solution to the problem?
Thanks
Lars Nielsen Lind

I have copied the PostgreSQL driver, commons-pool.jar, 
commons-collections.jar and commons-dbcp.jar  to the 
$CATALINA_HOME/common/lib folder.

I have done as specified in the JNDI Datasource HOW-TO.
*Server.xml*:

   
   


*Application Web.xml*:

   PostgreSQL DataSource
   jdbc/testdatabase
   javax.sql.DataSource
   Container

*Java component*:
import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.sql.*;
public class ConnectionPool {
  
   private Connection conn;

   public ConnectionPool() {}
   public Connection getConnectionFromPool() {
   try {
   InitialContext initContext = null;
  
   try {
   initContext = new InitialContext();
   } catch (Exception ex) {
   System.out.println("IC: " + ex);
   }

   try {
   DataSource ds = 
(DataSource)initContext.lookup("java:/comp/env/jdbc/testdatabase");
   conn = ds.getConnection();
   } catch (SQLException se) {
   System.out.println("DS: " + se);
   }
   } catch (NamingException ne) {
   System.out.println("NE: " + ne.getMessage());
   }
  
   return conn;
   }
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Tomcat 5.5.9 Connection Pool / JNDI / DBCP

2005-04-20 Thread David Smith
You should be doing this in your code:
Context initContext = null;
try {
 initContext = new InitialContext() ;
} catch ( Exception e1 ) { //... do something with the trapped exception }
try {
 DataSource ds = 
(DataSource)initContext.lookup("java:/comp/env/jdbc/testdatabase");
} catch ( Exception e2) { //... do something -- log it }
// Store a reference to ds someplace where it can be used over and over 
and over.

Note the only thing I really changed is to make the type of initContext 
Context instead of InitialContext.  This is mostly straight from the 
Tomcat 5.5 JNDI docs located here:

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html
--David
Lars Nielsen Lind wrote:
Hi.
I have some problems with Tomcat 5.5.9 Connection Pooling / JNDI / DBCP
When running my java component (se below) I receive this NamingException:
/NE: 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/

If I add this code:
System.setProperty("java.naming.factory.initial",  
"org.apache.naming.java.javaURLContextFactory");
System.setProperty("java.naming.factory.pkgs",  "org.apache.naming");

to the constructor in the java component, I receive this exception:
/NE: Name java: is not bound in this Context/
What is wrong and what is the solution to the problem?
Thanks
Lars Nielsen Lind

I have copied the PostgreSQL driver, commons-pool.jar, 
commons-collections.jar and commons-dbcp.jar  to the 
$CATALINA_HOME/common/lib folder.

I have done as specified in the JNDI Datasource HOW-TO.
*Server.xml*:

   
   


*Application Web.xml*:

   PostgreSQL DataSource
   jdbc/testdatabase
   javax.sql.DataSource
   Container

*Java component*:
import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.sql.*;
public class ConnectionPool {
 private Connection conn;
   public ConnectionPool() {}
   public Connection getConnectionFromPool() {
   try {
   InitialContext initContext = null;
 try {
   initContext = new InitialContext();
   } catch (Exception ex) {
   System.out.println("IC: " + ex);
   }
   try {
   DataSource ds = 
(DataSource)initContext.lookup("java:/comp/env/jdbc/testdatabase");
   conn = ds.getConnection();
   } catch (SQLException se) {
   System.out.println("DS: " + se);
   }
   } catch (NamingException ne) {
   System.out.println("NE: " + ne.getMessage());
   }
 return conn;
   }
 
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Tomcat 5.5.9 Connection Pool / JNDI / DBCP

2005-04-23 Thread Lars Nielsen Lind
I still can't make it work.
My /opt/jakarta-tomcat-5.5.9/logs/catalina.out display this message
2005-04-23 08:48:21 org.apache.commons.modeler.Registry registerComponent
SEVERE: Null component 
Catalina:type=DataSource,path=/,host=192.168.1.251,class=javax.sql.DataSource,name="jdbc/testdatabase"

And maybe that is the problem.
I have seen somewhere else that the Context part with the Resource is 
moved to a file called .xml. Some say to place in 
/META-INF, some say to place it in 
$CATALINA_HOME/conf/Catalina/localhost. I have tried both but it does 
not work for me.

When I remove the Context from my server.xml to a separate file - I see 
this when running Tomcat-Apache:No Host matches server name 
192.168.1.251.

Thanks
Lars Nielsen Lind

David Smith wrote:
You should be doing this in your code:
Context initContext = null;
try {
 initContext = new InitialContext() ;
} catch ( Exception e1 ) { //... do something with the trapped 
exception }
try {
 DataSource ds = 
(DataSource)initContext.lookup("java:/comp/env/jdbc/testdatabase");
} catch ( Exception e2) { //... do something -- log it }
// Store a reference to ds someplace where it can be used over and 
over and over.

Note the only thing I really changed is to make the type of 
initContext Context instead of InitialContext.  This is mostly 
straight from the Tomcat 5.5 JNDI docs located here:

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html
--David
Lars Nielsen Lind wrote:
Hi.
I have some problems with Tomcat 5.5.9 Connection Pooling / JNDI / DBCP
When running my java component (se below) I receive this 
NamingException:

/NE: 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/

If I add this code:
System.setProperty("java.naming.factory.initial",  
"org.apache.naming.java.javaURLContextFactory");
System.setProperty("java.naming.factory.pkgs",  "org.apache.naming");

to the constructor in the java component, I receive this exception:
/NE: Name java: is not bound in this Context/
What is wrong and what is the solution to the problem?
Thanks
Lars Nielsen Lind

I have copied the PostgreSQL driver, commons-pool.jar, 
commons-collections.jar and commons-dbcp.jar  to the 
$CATALINA_HOME/common/lib folder.

I have done as specified in the JNDI Datasource HOW-TO.
*Server.xml*:

   
   


*Application Web.xml*:

   PostgreSQL DataSource
   jdbc/testdatabase
   javax.sql.DataSource
   Container

*Java component*:
import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.sql.*;
public class ConnectionPool {
 private Connection conn;
   public ConnectionPool() {}
   public Connection getConnectionFromPool() {
   try {
   InitialContext initContext = null;
 try {
   initContext = new InitialContext();
   } catch (Exception ex) {
   System.out.println("IC: " + ex);
   }
   try {
   DataSource ds = 
(DataSource)initContext.lookup("java:/comp/env/jdbc/testdatabase");
   conn = ds.getConnection();
   } catch (SQLException se) {
   System.out.println("DS: " + se);
   }
   } catch (NamingException ne) {
   System.out.println("NE: " + ne.getMessage());
   }
 return conn;
   }
 
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]