RE: tomcat 4 datasource Oracle help

2001-08-22 Thread Peter Shankey

Pleae let me know how it goes for you as that is my goal for tomcat. However, 
currently I am struggling with mod_jk

Pete
[EMAIL PROTECTED] 


[EMAIL PROTECTED] (Jonathan Pierce) wrote:

I must still be missing something here. Please help. I'm still not able to get
an Oracle datasource using JNDI lookup to work. 

The lookup is returning null. Has anyone been successful looking up an Oracle
datasource resource using Tomcat 4.0b7?

I've placed the following jars in /common/lib

jdbc2_0-stdext.jar
tyrex-0.9.7.0.jar
classes12.jar (Oracle driver classes renamed from classes12.zip)

// My lookup code is:

theInitialContext = new InitialContext ();
DataSource theDataSource = (DataSource) theInitialContext.lookup
(java:comp/env/jdbc/oradb7);
out.println (theDataSource: + theDataSource);

I've configured server.xml as follows:

Context path=/frn docBase=frn debug=0
 reloadable=true
...
  Resource name=jdbc/oradb7 auth=SERVLET
type=javax.sql.DataSource /
  ResourceParams name=jdbc/oradb7
parameternameuser/namevaluetestuser/value/parameter
parameternamepassword/namevaluetestpassword/value/paramet
er
parameternamedriverClassName/name
  valueoracle.jdbc.driver.OracleDriver/value/parameter
parameternamedriverName/name
  valuejdbc:oracle:thin:@localhost:1521:ORADB7/value/parameter
  /ResourceParams

I've configured my apps web.xml file as follows:

web-app
...

resource-ref
descriptionDevelopment/description
res-ref-namejdbc/oradb7/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
res-sharing-scopeSharable/res-sharing-scope
/resource-ref

I also tried adding a factory parameter but I'm not sure if the value is
correct. The class oracle.jdbc.pool.OracleDataSourceFactory exists in the
classes.12.jar but I'm not sure if it is what I should be using as the factory
class.

  Context path=/frn docBase=frn debug=0
 reloadable=true
...
  Resource name=jdbc/oradb7 auth=SERVLET
type=javax.sql.DataSource /
  ResourceParams name=jdbc/oradb7
  parameternamefactory/name
  valueoracle.jdbc.pool.OracleDataSourceFactory/value/parameter

...


Reply Separator
Subject:RE: tomcat 4 datasource casting
Author: [EMAIL PROTECTED]
Date:   8/20/2001 6:42 PM

...and the second example for my class-not-found document presents itself
=)

Thanks guys!

- r

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Craig R.
 McClanahan
 Sent: Monday, August 20, 2001 6:16 PM
 To: [EMAIL PROTECTED]
 Subject: Re: tomcat 4 datasource casting


 Where do you have the jdbc2_0-stdext.jar file?  I'm betting that it needs
 to be in $CATALINA_HOME/common/lib only for this to work -- because JAR
 files here are on the class loading path for both Catalina internal
 classes and web application classes.

 Craig


 On Mon, 20 Aug 2001 [EMAIL PROTECTED] wrote:

  Hello all,
 
  I read the great message Craig McClanahan posted in the archives  (from
  Aug 4) about how to setup and use a tomcat 4 datasource.  All
 has seemed
  to go pretty well, but I'm having a funny problem, which I'm
 not sure is a
  Tyrex problem, a Tomcat 4 problem or a Java education problem
 on my part
  :).  (I'm using Tomcat 4 beta 7)
 
  When I try to get a DataSource from JNDI, I can retrieve a
 reference just
  fine.  The problem is that I am having trouble casting it to a
  javax.sql.DataSource.  It returns an instance of
  tyrex.jdbc.xa.EnabledDataSource.  If I try to cast to
  javax.sql.DataSource, I get a ClassCastException from the server.  I
  looked up this class in the Tyrex API docs, and it does in fact
 implement
  javax.sql.DataSource -- I think I should be able to cast to it
 because of
  that.  If I work with the tyrex implementation directly, all is
 ok (i.e.,
  calling tyrex.jdbc.xa.EnabledDataSource.getConnection()), but I
 obviously
  won't want to care about the particular implementation in this case.
 
  If it helps, here is the code I'm trying to use:
 
  --
  ctx = new InitialContext();
  ds = (DataSource)ctx.lookup(java:comp/env/jdbc/lis_ds);
  --
 
  That failed, so I added this for debugging:
 
  --
  Object o = ctx.lookup(java:comp/env/jdbc/lis_ds);
  if (o == null) {
 System.out.println(looked up a null object);
  } else {
 System.out.println(o is of type:  + o.getClass().getName()); //--
  prints tyrex.jdbc.xa.EnabledDataSource
  }
  --
 
  The exceptions I get are like this:
 
  --
  java.lang.ClassCastException: tyrex.jdbc.xa.EnabledDataSource
  at report.ReportPrefs.setDateDefaults(ReportPrefs.java:52)
  at 

Re:RE: tomcat 4 datasource Oracle help

2001-08-22 Thread Jonathan Pierce

I asked the question twice on this list and received no responses. I assume this
means noone has been successful doing this correctly.  Since I couldn't wait any
longer, I wrote a temporary solution that reads the properties directly and
allocates connections explicitly using the DriverManager.

Here's the code I ended up using to retrieve the DataSource properties. You can
use it as a temporary solution until someone responds to the correct way to
successfully instantiate the Oracle DataSource. I didn't include the
DBServletDataSourceSpec class here since it is not important to understanding
the implementation workaround.


private Vector ReadJNDIDataSources (HttpServlet theDBServletLogger)
throws Exception  
{
Vector  theResult = null;
String  theJNDIName = ;
String  theClassName = ;
String  theUserID = ;
String  thePassword = ;
String  theDriverName = ;
String  theDriverClassName = ;
NamingEnumeration   theNamingEnumeration = null;
Reference   theReference = null;
RefAddr theRefAddr = null;
Binding theBinding = null;
String  theResourceClassName = ;
DBServletDataSourceSpec theDBServletDataSourceSpec = null;
String  theURLConnectString = ;

theResult = new Vector ();
if (fInitialContext == null)
{
fInitialContext = new InitialContext ();
}
if (fComponentContext == null)
{
fComponentContext = (Context) fInitialContext.lookup
(java:comp/env);
}
theNamingEnumeration = fComponentContext.listBindings (jdbc);
theReference = null;
if (theDBServletLogger != null)
{
theDBServletLogger.log (DEBUG: Initializing Data Sources...);
}
while (theNamingEnumeration.hasMore ())
{
theBinding = (Binding) theNamingEnumeration.next ();
theJNDIName = theBinding.getName ();
theClassName = theBinding.getClassName ();
theReference = (Reference) theBinding.getObject ();
theResourceClassName  = (String) theReference.getClassName ();
if (theDBServletLogger != null)
{
theDBServletLogger.log (DEBUG: Adding DataSource...);
theDBServletLogger.log (DEBUG: Name:  + theJNDIName);
theDBServletLogger.log (DEBUG: Type:  + theClassName);
theDBServletLogger.log (DEBUG: Value:  + theReference);
theDBServletLogger.log (DEBUG: ResourceClassName:  +
theResourceClassName);
theDBServletLogger.log ();
}
if (theResourceClassName.equals (javax.sql.DataSource))
{
theRefAddr  = (RefAddr) theReference.get (user);
theUserID = (String) theRefAddr.getContent ();
theRefAddr  = (RefAddr) theReference.get (password);
thePassword = (String) theRefAddr.getContent ();
theRefAddr  = (RefAddr) theReference.get (driverName);
theDriverName = (String) theRefAddr.getContent ();
theRefAddr  = (RefAddr) theReference.get (driverClassName);
theDriverClassName = (String) theRefAddr.getContent ();
if (theDBServletLogger != null)
{
theDBServletLogger.log (DEBUG: theUserID:  + theUserID);
theDBServletLogger.log (DEBUG: thePassword:  +
thePassword);
theDBServletLogger.log (DEBUG: theDriverName:  +
theDriverName);
theDBServletLogger.log (DEBUG: theDriverClassName:  +
theDriverClassName);
}
theURLConnectString = theDriverName;
theDBServletDataSourceSpec = new DBServletDataSourceSpec
(theJNDIName
, theDriverClassName,
theURLConnectString, theUserID, thePassword);
theResult.addElement (theDBServletDataSourceSpec);
}
}
return (theResult);
} // DBServletDataSourceReader::ReadJNDIDataSources:


Reply Separator
Subject:RE: tomcat 4 datasource Oracle help
Author: [EMAIL PROTECTED]
Date:   8/22/2001 5:48 AM

Pleae let me know how it goes for you as that is my goal for tomcat. However,
currently I am struggling with mod_jk

Pete
[EMAIL PROTECTED] 


[EMAIL PROTECTED] (Jonathan Pierce) wrote:

I must still be missing something here. Please help. I'm still not able to get
an Oracle datasource using JNDI lookup to work. 

The lookup is returning null. Has anyone been successful looking up an Oracle
datasource resource using Tomcat 4.0b7?

I've placed the following jars in /common/lib

tomcat 4 datasource Oracle help

2001-08-20 Thread Jonathan Pierce

I must still be missing something here. Please help. I'm still not able to get
an Oracle datasource using JNDI lookup to work. 

The lookup is returning null. Has anyone been successful looking up an Oracle
datasource resource using Tomcat 4.0b7?

I've placed the following jars in /common/lib

jdbc2_0-stdext.jar
tyrex-0.9.7.0.jar
classes12.jar (Oracle driver classes renamed from classes12.zip)

// My lookup code is:

theInitialContext = new InitialContext ();
DataSource theDataSource = (DataSource) theInitialContext.lookup
(java:comp/env/jdbc/oradb7);
out.println (theDataSource: + theDataSource);

I've configured server.xml as follows:

Context path=/frn docBase=frn debug=0
 reloadable=true
...
  Resource name=jdbc/oradb7 auth=SERVLET
type=javax.sql.DataSource /
  ResourceParams name=jdbc/oradb7
parameternameuser/namevaluetestuser/value/parameter
parameternamepassword/namevaluetestpassword/value/paramet
er
parameternamedriverClassName/name
  valueoracle.jdbc.driver.OracleDriver/value/parameter
parameternamedriverName/name
  valuejdbc:oracle:thin:@localhost:1521:ORADB7/value/parameter
  /ResourceParams

I've configured my apps web.xml file as follows:

web-app
...

resource-ref
descriptionDevelopment/description
res-ref-namejdbc/oradb7/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
res-sharing-scopeSharable/res-sharing-scope
/resource-ref

I also tried adding a factory parameter but I'm not sure if the value is
correct. The class oracle.jdbc.pool.OracleDataSourceFactory exists in the
classes.12.jar but I'm not sure if it is what I should be using as the factory
class.

  Context path=/frn docBase=frn debug=0
 reloadable=true
...
  Resource name=jdbc/oradb7 auth=SERVLET
type=javax.sql.DataSource /
  ResourceParams name=jdbc/oradb7
  parameternamefactory/name
  valueoracle.jdbc.pool.OracleDataSourceFactory/value/parameter

...


Reply Separator
Subject:RE: tomcat 4 datasource casting
Author: [EMAIL PROTECTED]
Date:   8/20/2001 6:42 PM

...and the second example for my class-not-found document presents itself
=)

Thanks guys!

- r

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Craig R.
 McClanahan
 Sent: Monday, August 20, 2001 6:16 PM
 To: [EMAIL PROTECTED]
 Subject: Re: tomcat 4 datasource casting


 Where do you have the jdbc2_0-stdext.jar file?  I'm betting that it needs
 to be in $CATALINA_HOME/common/lib only for this to work -- because JAR
 files here are on the class loading path for both Catalina internal
 classes and web application classes.

 Craig


 On Mon, 20 Aug 2001 [EMAIL PROTECTED] wrote:

  Hello all,
 
  I read the great message Craig McClanahan posted in the archives  (from
  Aug 4) about how to setup and use a tomcat 4 datasource.  All
 has seemed
  to go pretty well, but I'm having a funny problem, which I'm
 not sure is a
  Tyrex problem, a Tomcat 4 problem or a Java education problem
 on my part
  :).  (I'm using Tomcat 4 beta 7)
 
  When I try to get a DataSource from JNDI, I can retrieve a
 reference just
  fine.  The problem is that I am having trouble casting it to a
  javax.sql.DataSource.  It returns an instance of
  tyrex.jdbc.xa.EnabledDataSource.  If I try to cast to
  javax.sql.DataSource, I get a ClassCastException from the server.  I
  looked up this class in the Tyrex API docs, and it does in fact
 implement
  javax.sql.DataSource -- I think I should be able to cast to it
 because of
  that.  If I work with the tyrex implementation directly, all is
 ok (i.e.,
  calling tyrex.jdbc.xa.EnabledDataSource.getConnection()), but I
 obviously
  won't want to care about the particular implementation in this case.
 
  If it helps, here is the code I'm trying to use:
 
  --
  ctx = new InitialContext();
  ds = (DataSource)ctx.lookup(java:comp/env/jdbc/lis_ds);
  --
 
  That failed, so I added this for debugging:
 
  --
  Object o = ctx.lookup(java:comp/env/jdbc/lis_ds);
  if (o == null) {
 System.out.println(looked up a null object);
  } else {
 System.out.println(o is of type:  + o.getClass().getName()); //--
  prints tyrex.jdbc.xa.EnabledDataSource
  }
  --
 
  The exceptions I get are like this:
 
  --
  java.lang.ClassCastException: tyrex.jdbc.xa.EnabledDataSource
  at report.ReportPrefs.setDateDefaults(ReportPrefs.java:52)
  at report.ReportPrefs.init(ReportPrefs.java:16)
  at java.lang.Class.newInstance0(Native Method)
  at java.lang.Class.newInstance(Class.java:237)
  at java.beans.Beans.instantiate(Beans.java:207)
  at