dcsimg
Cannot obtain a DataSource through JNDI
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Freddy_Villalba
Posted On:   Wednesday, April 7, 2004 02:59 AM

hi, I'm running a web application on JBuilder / Tomcat 4.1 / JDK1.3.1 / J2EE 1.3.1. I'm trying to obtain a DB connection from a DataSource, but I can't seem to JNDI-lookup the DataSource. I've tested obtaining a Connection using the "DriverManager way" and it works. This is the code on my server8080.xml file: <?xml version="1.0" encoding="UTF-8"?> username ****    More>>

hi,




I'm running a web application on JBuilder / Tomcat 4.1 / JDK1.3.1 / J2EE 1.3.1.




I'm trying to obtain a DB connection from a DataSource, but I can't seem to JNDI-lookup the DataSource. I've tested obtaining a Connection using the "DriverManager way" and it works.




This is the code on my server8080.xml file:




<?xml version="1.0" encoding="UTF-8"?>



































username


****








password


****








driverClassName




oracle.jdbc.driver.OracleDriver








url







jdbc:oracle:thin:@BMSRVORACLE:1521:BMSRVMS































This is the code in my web.xml file:




<?xml version="1.0" encoding="UTF-8"?>








Testing





debugjsp


Added to compile JSPs with debug info


org.apache.jasper.servlet.JspServlet





classdebuginfo


true





3








debugjsp


*.jsp








Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.


jdbc/SGC_CNID


javax.sql.DataSource


Container












This is the java code:






ContextWrapper ctxW = Globals.getContextWrapper();

Context ctx = ctxW.getContext();



String dsName = "jdbc/SGC_CNID";



try {

DataSource ds = (DataSource) ctx.lookup(dsName);

return ds.getConnection();

} catch (NamingException ne) {

throw new UselessResourceException("No se puede recuperar el DataSource '"+dsName+"'.", ne);

} catch (SQLException sqle) {

throw new UselessResourceException("ERROR: No se puede obtener una Connection del DataSource '"+dsName+"'.", sqle);

}





ctxW.getContext() (successfully finds and) returns the "java:comp/env" entry, restored by the following piece of code:




try {

Context initCtx = new InitialContext();

Context envCtx = (Context) initCtx.lookup("java:comp/env");

this.setContext(envCtx);

} catch (NamingException ne) {

throw new LinkedRuntimeException("No se pudo construir el Context Wrapper.", ne);

}







WHAT'S HAPPENING HERE???



THANKS EVERYBODY!


Freddy.

   <<Less

Re: Cannot obtain a DataSource through JNDI

Posted By:   Freddy_Villalba  
Posted On:   Monday, April 12, 2004 04:01 AM

I have solved it. The Tomcat 4.1 packed with JBuilder X did not include some jars (DBCP and related).

Now I have another problem: I'm successfully looking up the DataSource, but the properties are not there!!!

Any thoughts anybody?

Re: Cannot obtain a DataSource through JNDI

Posted By:   Freddy_Villalba  
Posted On:   Wednesday, April 7, 2004 03:51 AM

I forgot to mention that I haven't installed DBCP or any other connection pooling solution. Is this mandatory or does Tomcat provide a default CP solution?
About | Sitemap | Contact