Re: JNDI/Tomcat question from newbie

2005-09-01 Thread David Smith
Personally, I'd just keep a reference to the datasource around maybe as
a class instance variable.  It doesn't constitute a connection in and of
itself -- just a way of getting one from the pool.  Connections on the
other hand should be explicitly closed as soon as they aren't needed
anymore in any method that get's one.

--David

Hyatt, Gordon wrote:

Hello All,

I'm a newbie to database pooling via JNDI and I have a JNDI/Tomcat question 
(more of a best practices/most scalable/fastest performance/least resource 
consumption type of question).

Each time the JNDI resource (pooled database connection) is needed, should a 
complete JNDI lookup be performed or can part of the lookup be cached?  For 
example, should the code be:

code
Context initCtx = new InitialContext ();
Context envCtx = (Context)initCtx.lookup (java:comp/env);
ds = (DataSource)envCtx.lookup (jdbc/data_source_name);

/code

or can the java:comp/env Context be saved as an attribute in the servlet 
context and a (synchronized) code segment like the following be used to obtain 
the DataSource?

code
Context ctx = (Context)ctxFromServletContext.lookup ();
ds = (DataSource)ctx.lookup (jdbc/data_source_name);
/code

Thus far, I haven't read anything about which method is acceptable/preferred 
or if one method yields significant performance benefit.  

Since, according to the docs a Context is not guaranteed to be synchronized 
against concurrent access by multiple threads, I assume that the first code 
segment above should be synchronized, especially if it is in a static method.

Thanks in advance,

Gord 

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

  



-- 
===
David Smith
Network Operations Supervisor
Department of Entomology
College of Agriculture  Life Sciences
Cornell University
2132 Comstock Hall
Ithaca, NY  14853
Phone: 607.255.9571
Fax: 607.255.0939


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



Re: JNDI - TOMCAT

2005-07-27 Thread Tim Funk

Don't use docs based on 4.1 when running 5.5.

Use the 5.5 docs. The way JNDI resources are declared in 5.5 changed as 
compared to previous versions. The archives in the tomcat user list also talk 
about this too.

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/index.html

-Tim

Kane Wilson wrote:

Hi List , 
 
This is actually problem with JNDI . I'm tring to connect to mysql database via JNDI in tomcat 5.5.9. First of all 
i installed tomcat 5.5.9 in my windows 2000 advance server machine and accrding to guide of  
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html url , I  have done every thng 
according to the article.

my sql connector is mysql-connector-java-3.1.10-bin.jar C:\Tomcat\common\lib
after all the steps get done , i pointed to the  test.jsp
but i got an error saying ,
DataSource invalid: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for 
connect URL 'null'

===
so then i surf the internet to findout a soloution , there are plenty of such issues and some closest solutions  
with crerating .war files , changing some parameters like that .

http://www.theserverside.com/tss?service=direct/0/DiscussionThread/threadViewer.bookmark.linksp=l29795
but , i would like to ask from directly  from jakarta.apache.org/tomcat  , do u have sudgested a solution for this 
matter / problem ? is it a bug in that particular version ( 5.5.9 ) ? do i have to switched for another version ?
is that problem of curruption of mysql connector ? 
can i findout any one who has already solved this issue ?
I read well FAQ's rules and regulations . i agreed with that . and i think , this issue has discussed couple of 
times in this list. but i cant findout exactly how could be the solution was ! .

Please help me , it's really appreciate if u guys can consider this problem 
deeply .
 
Thanx in advance for Tomcat and the LIST ,

Kane.


-
 Start your day with Yahoo! - make it your home page 


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



Re: JNDI - TOMCAT ------ success

2005-07-27 Thread Kane Wilson
Tim , it was success. thanx million. earlier i referred 5.0 docs. anyway it was 
my fault. again i would like to thank you Tim. It is great help
 
Kane.
 
  

Tim Funk [EMAIL PROTECTED] wrote:
Don't use docs based on 4.1 when running 5.5.

Use the 5.5 docs. The way JNDI resources are declared in 5.5 changed as 
compared to previous versions. The archives in the tomcat user list also talk 
about this too.
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/index.html

-Tim

Kane Wilson wrote:

 Hi List , 
 
 This is actually problem with JNDI . I'm tring to connect to mysql database 
 via JNDI in tomcat 5.5.9. First of all 
 i installed tomcat 5.5.9 in my windows 2000 advance server machine and 
 accrding to guide of 
 http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
  url , I have done every thng 
 according to the article.
 my sql connector is mysql-connector-java-3.1.10-bin.jar C:\Tomcat\common\lib
 after all the steps get done , i pointed to the test.jsp
 but i got an error saying ,
 DataSource invalid: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot 
 create JDBC driver of class '' for 
 connect URL 'null'
 ===
 so then i surf the internet to findout a soloution , there are plenty of such 
 issues and some closest solutions 
 with crerating .war files , changing some parameters like that .
 http://www.theserverside.com/tss?service=direct/0/DiscussionThread/threadViewer.bookmark.linksp=l29795
 but , i would like to ask from directly from jakarta.apache.org/tomcat , do u 
 have sudgested a solution for this 
 matter / problem ? is it a bug in that particular version ( 5.5.9 ) ? do i 
 have to switched for another version ?
 is that problem of curruption of mysql connector ? 
 can i findout any one who has already solved this issue ?
 I read well FAQ's rules and regulations . i agreed with that . and i think , 
 this issue has discussed couple of 
 times in this list. but i cant findout exactly how could be the solution was 
 ! .
 Please help me , it's really appreciate if u guys can consider this problem 
 deeply .
 
 Thanx in advance for Tomcat and the LIST ,
 Kane.
 
 
 -
 Start your day with Yahoo! - make it your home page 

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


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: JNDI + Tomcat + Oracle 9i Database

2003-02-25 Thread Mehdi . Nejad

Hi [difficult name ommited],

I had this problem a couple of weeks ago.

try changing the url to capitals !

nameURL/name

This fixed an identical problem for me.

Thanks,

Mehdi Nejad



   
   
  Sebastião Carlos
   
  Santos  To:   [EMAIL PROTECTED] 
  
  [EMAIL PROTECTED]cc:

  .com.br Subject:  JNDI + Tomcat + Oracle 9i 
Database   
   
   
  25/02/2003 15:02 
   
  Please respond to
   
  Tomcat Users
   
  List
   
   
   
   
   




I am trying to configure JNDI to access Oracle 9i R1,
according to JNDI Datasource HOW-TO,
however I am not obtaining a lot of success when I go
to establish the connection.

In the end of this e-mail I will list some fragments of the configuration
of server.xml,
web.xml and of my class java that I am using to accomplish the connection
test.

The reference $CATALINA_HOME/common/lib/*. jar is in CLASSPATH of the
system

Fragment of configuration of server.xml

...
  Resource name=jdbc/sged auth=Container
type=javax.sql.DataSource/
  ResourceParams name=jdbc/sged
parameternamefactory/name

valueorg.apache.commons.dbcp.BasicDataSourceFactory/value/parameter
parameternamedriverClassName/name
  valueoracle.jdbc.driver.OracleDriver/value/parameter
parameternameurl/name

valuejdbc:oracle:[EMAIL PROTECTED]:1521:XXX/value/parameter

parameternameusername/namevaluescott/value/parameter

parameternamepassword/namevaluej/value/parameter
parameternamemaxActive/namevalue20/value/parameter
parameternamemaxIdle/namevalue10/value/parameter
parameternamemaxWait/namevalue1/value/parameter

parameternameremoveAbandoned/namevaluetrue/value/parameter

parameternameremoveAbandonedTimeout/namevalue60/value/parameter

parameternamelogAbandoned/namevaluetrue/value/parameter
  /ResourceParams
...

File /web/WEB-INF/web.xml

?xml version=1.0 encoding=ISO-8859-1?
  !DOCTYPE web-app PUBLIC
-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
http://java.sun.com/dtd/web-app_2_3.dtd;
  web-app
descriptionOracle Database Connection/description
resource-ref
  descriptionPool/description
  res-ref-namejdbc/sged/res-ref-name
  res-typejavax.sql.DataSource/res-type
  res-authContainer/res-auth
/resource-ref
welcome-file-list
  welcome-fileindex.html/welcome-file
  welcome-fileindex.jsp/welcome-file
  welcome-fileindex.htm/welcome-file
/welcome-file-list
  /web-app


Method of the class java that makes the connection test

public String obtem_dados()
{
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
resultado = new StringBuffer();
try
{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup
(java:/comp/env);
DataSource ds = (DataSource)envContext.lookup
(jdbc/sged);
conn = ds.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery(SELECT COUNT(*) FROM
V$SESSION);
if (rset.next())
{
resultado.append(Número de Conexões - );
resultado.append(rset.getString(1));
resultado.append(br);
}
}
catch (java.lang.Exception e)
{

Re: JNDI + Tomcat + Oracle 9i Database

2003-02-25 Thread Sebastião Carlos Santos
When I made the change of the nameurl / name for nameURL / name I started to 
receive the following error message
Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' it goes connect 
URL 'null'
Going back to the configuration nameurl / name
Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' it goes connect 
URL 'jdbc:oracle:[EMAIL PROTECTED]:1521:GED'

Taking advantage of the opportunity, which driver JDBC should use, ojdbc14.jar (for 
the jdk 1.4) or classes12.zip, that should have the name according to the 
documentation changed for classes12.jar

Sebastião Carlos Santos
Oracle Database Administrator
Universidade Federal de Uberlândia - UFU
Gratificação de Estímulo à Docência - GED



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



Re: JNDI + Tomcat + Oracle 9i Database

2003-02-25 Thread Sebastião Carlos Santos
Kris,
 I believe that I went badly interpreted or I wrote of less in the e-mail. I don't see 
him/it why of installing the customer of Oracle 9i in the application servant for the 
simple fact most of the time, after the installation routines we have to specify the 
files. zip and. jar copied in the installation for ORACLE_HOME in CLASSPATH of the 
system, which in other words it would be the same thing of using the drivers jdbc 
supplied separately.
 I didn't have the intention of contradicting the positioning for you put.
 Respectfully,
Sebastião Carlos Santos
Oracle Database Administrator
Universidade Federal de Uberlândia - UFU
Gratificação de Estímulo à Docência - GED



RE: JNDI + Tomcat + Oracle 9i Database

2003-02-25 Thread pqin
This issue has been asked and answered again and again in the mailing list
of tomcat, struts, and commons. Consider that Oracle is so populate, setup
should be pretty straightforward.

My advice is to make sure that you have read carefully the tomcat datasource
documentation.

My environment is

J2sdk 1.4.1_01 = 1.4
Tomcat 4.1.18
Apache 2.0.44
Tomcat Connector 2.0.3
Red Hat Linux 7.2 (prod)
Windows 2000 (dev)
Oracle 8.1.7
classes12.jar = 1.2

1. Below is part of my context. Do not invent the resource type, driver, and
factory. I saw someone use a different factory or driver think they are
going to utilize Oracle's pooling. It is smart but it is wrong in this case.
To prove it is wrong, read Tomcat source code.

Resource name=jdbc/abcd
auth=Container
type=javax.sql.DataSource/ 

ResourceParams name=jdbc/abcd
parameter
namedriverClassName/name
valueoracle.jdbc.driver.OracleDriver/value
/parameter
parameter
nameurl/name
valuejdbc:oracle:thin:@oratest.int.abcd.com:1521:PROD/value
/parameter

2. Also in my app's web.xml

resource-ref
descriptionOracle Datasource/description
res-ref-namejdbc/abcd/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
/resource-ref

Do not put commons-dbcp and pooling jars in your app's WEB-INF/lib, use
Tomcat's (in common/lib).

3. Initialize the connection pool and get connection:

Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup(java:comp/env);
DataSource dataSource = (DataSource) envContext.lookup(jdbc/abcd);
dataSource.getConnection()

Don't do anything other than point 3 to get the connection or driver.

I have had two problems before:

- null driver: renamed classes12.zip to classes12.jar and put it ONLY in
commons/lib.
- cannot connect: use a real url other than Microsoft's name, so oratest
won't work on linux while oratest.mydomain.com works.
- cast exception: use commons dbcp and pooling in commons/lib.


Regards,
 
 
PQ
 
This Guy Thinks He Knows Everything
This Guy Thinks He Knows What He Is Doing

-Original Message-
From: Sebastião Carlos Santos [mailto:[EMAIL PROTECTED] 
Sent: February 25, 2003 1:37 PM
To: [EMAIL PROTECTED]
Subject: Re: JNDI + Tomcat + Oracle 9i Database

When I made the change of the nameurl / name for nameURL / name I
started to receive the following error message  
Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' it goes
connect URL 'null'  
Going back to the configuration nameurl / name  
Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' it goes
connect URL 'jdbc:oracle:[EMAIL PROTECTED]:1521:GED'

Taking advantage of the opportunity, which driver JDBC should use,
ojdbc14.jar (for the jdk 1.4) or classes12.zip, that should have the name
according to the documentation changed for classes12.jar

Sebastião Carlos Santos
Oracle Database Administrator 
Universidade Federal de Uberlândia - UFU
Gratificação de Estímulo à Docência - GED



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