RE: JNDI and/or pooling help (long post)

2002-07-14 Thread Vikramjit Singh

In tomcat 4.0.3 even i faced the same problem, in which i was getting
DataSource = null. 
Then when i upgraded to TC 4.1.7, i got the DataSource object. Why dont you
also upgrade and see.


-Original Message-
From: Turner, John [mailto:[EMAIL PROTECTED]]
Sent: Saturday, July 13, 2002 10:58 AM
To: 'Tomcat Users List'
Subject: RE: JNDI and/or pooling help (long post)



Thanks for the reply.  I've changed my server.xml Resource object to match
yours (aside from things like username, etc) and still no luck.

As far as I can tell, the Context lookup is working, but when I execute this
line of code, I get nothing (null):

DataSource ds = null;
ds = (DataSource)ctx.lookup(java:comp/env/jdbc/MyTestDB);

I'm at a loss as to explain what's going on.  There's nothing in any of the
log files, erverything looks great.  I just can't get a valid DataSource
object, which means I can't get a connection.

Does anyone have any thoughts on what might be going on?  This is very
frustrating...I can't even tell if it's a problem with my tomcat
configuration, my servlet code, the driver, whatever...there aren't any
error messages, just null.

John Turner
[EMAIL PROTECTED]

-Original Message-
From: Andrew Conrad [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 7:15 PM
To: 'Tomcat Users List'
Subject: RE: JNDI and/or pooling help (long post)


Also, check your URL. The syntax is also UserName (case-insensitive) 

Here's my working resource:

ResourceParams name=jdbc/DataStorage
 parameter
  nameurl/name
  valuejdbc:microsoft:sqlserver://localhost:1433/value
 /parameter
 parameter
   namevalidationQuery/name
   valueselect * from organizations/value
 /parameter
 parameter
   namemaxIdle/name
   value2/value
 /parameter
 parameter
   namemaxActive/name
   value10/value
 /parameter
 parameter
   namedriverClassName/name
   valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
 /parameter
 parameter
   namemaxWait/name
   value5000/value
 /parameter
 parameter
   nameusername/name
   valueAndrew/value
 /parameter
 parameter
   namepassword/name
   value12345/value
 /parameter
/ResourceParams

Then, once I get the DataSource, then the connection, I do a
setCatalog() to define the correct DB.

- Andrew


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

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




RE: JNDI and/or pooling help (long post)

2002-07-13 Thread Turner, John


Thanks for the reply.  I've changed my server.xml Resource object to match
yours (aside from things like username, etc) and still no luck.

As far as I can tell, the Context lookup is working, but when I execute this
line of code, I get nothing (null):

DataSource ds = null;
ds = (DataSource)ctx.lookup(java:comp/env/jdbc/MyTestDB);

I'm at a loss as to explain what's going on.  There's nothing in any of the
log files, erverything looks great.  I just can't get a valid DataSource
object, which means I can't get a connection.

Does anyone have any thoughts on what might be going on?  This is very
frustrating...I can't even tell if it's a problem with my tomcat
configuration, my servlet code, the driver, whatever...there aren't any
error messages, just null.

John Turner
[EMAIL PROTECTED]

-Original Message-
From: Andrew Conrad [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 7:15 PM
To: 'Tomcat Users List'
Subject: RE: JNDI and/or pooling help (long post)


Also, check your URL. The syntax is also UserName (case-insensitive) 

Here's my working resource:

ResourceParams name=jdbc/DataStorage
 parameter
  nameurl/name
  valuejdbc:microsoft:sqlserver://localhost:1433/value
 /parameter
 parameter
   namevalidationQuery/name
   valueselect * from organizations/value
 /parameter
 parameter
   namemaxIdle/name
   value2/value
 /parameter
 parameter
   namemaxActive/name
   value10/value
 /parameter
 parameter
   namedriverClassName/name
   valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
 /parameter
 parameter
   namemaxWait/name
   value5000/value
 /parameter
 parameter
   nameusername/name
   valueAndrew/value
 /parameter
 parameter
   namepassword/name
   value12345/value
 /parameter
/ResourceParams

Then, once I get the DataSource, then the connection, I do a
setCatalog() to define the correct DB.

- Andrew


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




RE: JNDI and/or pooling help (long post)

2002-07-13 Thread Andrew Conrad

Where are you putting your Resource?  Are you putting it inside your
Context element, or in the GlobalResources Element ?

For a simple configuration, nest it inside your Context.


ie

Context path=/test docBase=test
Resource

/Resource
ResourceParams
...
/ResourceParams
/Context


Also, is your try-catch block catching an exception that might help
point to the problem?



- Andrew

-Original Message-
From: Turner, John [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, July 13, 2002 1:58 PM
To: 'Tomcat Users List'
Subject: RE: JNDI and/or pooling help (long post)



Thanks for the reply.  I've changed my server.xml Resource object to
match yours (aside from things like username, etc) and still no luck.

As far as I can tell, the Context lookup is working, but when I execute
this line of code, I get nothing (null):

DataSource ds = null;
ds = (DataSource)ctx.lookup(java:comp/env/jdbc/MyTestDB);

I'm at a loss as to explain what's going on.  There's nothing in any of
the log files, erverything looks great.  I just can't get a valid
DataSource object, which means I can't get a connection.

Does anyone have any thoughts on what might be going on?  This is very
frustrating...I can't even tell if it's a problem with my tomcat
configuration, my servlet code, the driver, whatever...there aren't any
error messages, just null.

John Turner
[EMAIL PROTECTED]

-Original Message-
From: Andrew Conrad [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 7:15 PM
To: 'Tomcat Users List'
Subject: RE: JNDI and/or pooling help (long post)


Also, check your URL. The syntax is also UserName (case-insensitive)

Here's my working resource:

ResourceParams name=jdbc/DataStorage
 parameter
  nameurl/name
  valuejdbc:microsoft:sqlserver://localhost:1433/value
 /parameter
 parameter
   namevalidationQuery/name
   valueselect * from organizations/value
 /parameter
 parameter
   namemaxIdle/name
   value2/value
 /parameter
 parameter
   namemaxActive/name
   value10/value
 /parameter
 parameter
   namedriverClassName/name
   valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
 /parameter
 parameter
   namemaxWait/name
   value5000/value
 /parameter
 parameter
   nameusername/name
   valueAndrew/value
 /parameter
 parameter
   namepassword/name
   value12345/value
 /parameter
/ResourceParams

Then, once I get the DataSource, then the connection, I do a
setCatalog() to define the correct DB.

- Andrew


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


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




Re: JNDI and/or pooling help (long post)

2002-07-13 Thread Jacob Kjome

Hi John,
I'm attaching my context configuration file (CCF) that I use with
Tomcat-4.1.x. It works perfectly for me. If you are using
Tomcat-4.1.x, you can put both your context directory and the attached
CCF (modified to your needs) in TOMCAT_HOME/webapps. Or, you can
add the Context inside the CCF to your server.xml if you are
using Tomcat-4.0.x. The configuration for your web.xml and the
syntax of how you access your datasource using Java code is commented out
inside the CCF for your reference.
BTW, make sure you put your DB Driver in TOMCAT_HOME/common/lib because
both your server and your app need access to the driver.
Also, if you try using Tomcat-4.1.7, DBCP doesn't seem to work (at least
not for me) with the commons-dbcp.jar that comes with it. I copied
the commons-dbcp.jar from Tomcat-4.1.3 over the one in 4.1.7 and things
started working again. Hopefully that is fixed by the next
release.
I can't tell you much about using DBCP with Tomcat-4.0.x. One thing
I'd recommend, though, is upgrading to, at least, Tomcat-4.0.4.
Many, many important bugs are fixed including some classloading
bugs. What I really recommend is moving to Tomcat-4.1.7 and using
the DBCP workaround I mentioned above. The DBCP issue was the only
thing I've found not working as I expected. It is a very stable
release from what I can tell.
Good luck!
Jake
At 03:36 PM 7/12/2002 -0400, you wrote:
Hello -
I'm having problems getting a connection to my database using JNDI
and
various pooling mechanisms. I'm using tomcat 4.0.3 standalone on
Win2K.
First, let me say that I can access my database (SQL Server 2000) using
the
Microsoft JDBC Type 4 driver without any problems if I put the
connection
code right in my servlet (Class.forName, etc.). If I do that, no
problems.
It's only when I try and move the database connection code up to an
application scope or use pooling that I run into problems. I've
setup JNDI
according to the Jakarta-Tomcat HOW-TO.
I've tried DBCP/pool according to this link:
http://marc.theaimsgroup.com/?l=tomcat-userm=102225547106556w=2
I also tried the solution from here:
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/c
onpool.html
And I also tried the DBConnectionBroker from javaexchange.com, as well
as
the DataSourceWrapper/ConnectionPool classes from the O'Reilly JSP
book.
I've even tried setting up DriverName, URL, username, and password
as
servlet parameters in web.xml and writing an init servlet
that would read
them in, create the datasource, and then push the datasource into
the
application scope with getServletContext().setAttribute(). That
didn't
work, either.
I would definitely appreciate any help or suggestions, I'm going
crazy
trying to figure out what is wrong. I don't really even need the
pooling,
but what I want to do is get the specific database parameters
(username,
password, host, etc.) OUT of the servlets (and beans). I want
other
developers to just be able to grab a handle to the datasource, open
a
connection, and use it without having to know any specific information
about
the database and the parameters.
Here's my server.xml (with the DBCP/pool) setup:
Resource name=jdbc/MyTestDB auth=Container
type=javax.sql.DataSource
/
ResourceParams name=jdbc/MyTestDB
 parameter
 namefactory/name

valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
 /parameter

parameternamemaxActive/namevalue100/value/parameter

parameternamemaxIdle/namevalue3/value/parameter

parameternamemaxWait/namevalue100/value/parameter
 parameter
 nameuser/name
 valuesome_user/value
 /parameter
 parameter
 namepassword/name

valuesome_password/value
 /parameter
 parameter
 
namedatabasename/name
 valuesome_db/value
 /parameter
 parameter

namedriverClassName/name

valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
 /parameter
 parameter
 nameurl/name

valuejdbc:microsoft:sqlserver://SOMEHOST:1433;User=some_user;Password=some
_password;DatabaseName=some_db/value --
 /parameter
/ResourceParams
Here is my web.xml:
 resource-ref
 descriptionDB
Connection/description

res-ref-namejdbc/MyTestDB/res-ref-name

res-typejavax.sql.DataSource/res-type
 res-authContainer/res-auth
 /resource-ref

In every case above, regardless of the pooling mechanism, or even
just
trying to setup a datasource as an application scope object, I get either
an
error message, or null. In the config above, I get null. The
code I use
with the config above looks like this:
As a test, I wrote a little JNDI reader servlet that just enumerates
over
the JNDI space and lists out the objects:
try {
 Context initCtx = new InitialContext();
 NamingEnumeration enum =
initCtx.listBindings(java:comp/env/jdbc);
 
 while (enum.hasMore()) {
 Binding binding = (Binding)
enum.next();
 out.println(Name: 
+ binding.getName() + br);
 out.println(Type: 
+ binding.getClassName() + br);
 out.println(Value:
 + binding.getObject() + br);
 out.println();
 out.println();
 }
} catch (NamingException e) {
 out.println(Naming
Exception:  + e.getMessage());

RE: JNDI and/or pooling help (long post)

2002-07-12 Thread Andrew Conrad

Dfor my Resource Object, I was only ever able to use the param
username, not user.


- Andrew

-Original Message-
From: Turner, John [mailto:[EMAIL PROTECTED]] 
Sent: Friday, July 12, 2002 3:37 PM
To: '[EMAIL PROTECTED]'
Subject: JNDI and/or pooling help (long post)



Hello -

I'm having problems getting a connection to my database using JNDI and
various pooling mechanisms. I'm using tomcat 4.0.3 standalone on Win2K.
First, let me say that I can access my database (SQL Server 2000) using
the Microsoft JDBC Type 4 driver without any problems if I put the
connection code right in my servlet (Class.forName, etc.).  If I do
that, no problems. It's only when I try and move the database connection
code up to an application scope or use pooling that I run into problems.
I've setup JNDI according to the Jakarta-Tomcat HOW-TO.

I've tried DBCP/pool according to this link:
http://marc.theaimsgroup.com/?l=tomcat-userm=102225547106556w=2

I also tried the solution from here:
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBo
ok/c
onpool.html

And I also tried the DBConnectionBroker from javaexchange.com, as well
as the DataSourceWrapper/ConnectionPool classes from the O'Reilly JSP
book.

I've even tried setting up DriverName, URL, username, and password as
servlet parameters in web.xml and writing an init servlet that would
read them in, create the datasource, and then push the datasource into
the application scope with getServletContext().setAttribute().  That
didn't work, either.

I would definitely appreciate any help or suggestions, I'm going crazy
trying to figure out what is wrong.  I don't really even need the
pooling, but what I want to do is get the specific database parameters
(username, password, host, etc.) OUT of the servlets (and beans).  I
want other developers to just be able to grab a handle to the
datasource, open a connection, and use it without having to know any
specific information about the database and the parameters.

Here's my server.xml (with the DBCP/pool) setup:

Resource name=jdbc/MyTestDB auth=Container
type=javax.sql.DataSource / ResourceParams name=jdbc/MyTestDB
parameter
  namefactory/name
  valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
/parameter
parameternamemaxActive/namevalue100/value/parameter
parameternamemaxIdle/namevalue3/value/parameter
parameternamemaxWait/namevalue100/value/parameter
parameter
  nameuser/name
  valuesome_user/value
/parameter
parameter
  namepassword/name
  valuesome_password/value
/parameter
parameter
  namedatabasename/name
  valuesome_db/value
/parameter
parameter
  namedriverClassName/name
  valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
/parameter
parameter
  nameurl/name
 
valuejdbc:microsoft:sqlserver://SOMEHOST:1433;User=some_user;Password=
some
_password;DatabaseName=some_db/value --
/parameter
/ResourceParams

Here is my web.xml:

  resource-ref
descriptionDB Connection/description
res-ref-namejdbc/MyTestDB/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
  /resource-ref

In every case above, regardless of the pooling mechanism, or even just
trying to setup a datasource as an application scope object, I get
either an error message, or null.  In the config above, I get null.  The
code I use with the config above looks like this:

As a test, I wrote a little JNDI reader servlet that just enumerates
over the JNDI space and lists out the objects:

try {
Context initCtx = new InitialContext();
NamingEnumeration enum = initCtx.listBindings(java:comp/env/jdbc);

while (enum.hasMore()) {
Binding binding = (Binding) enum.next();
out.println(Name:  + binding.getName() + br);
out.println(Type:  + binding.getClassName() + br);
out.println(Value:  + binding.getObject() + br);
out.println();
out.println();
}
} catch (NamingException e) {
out.println(Naming Exception:  + e.getMessage());
}

When I run this servlet, I get output that says:

Name: MyTestDB
Type: org.apache.naming.ResourceRef
Value: Reference Class Name: javax.sql.DataSource Type: description
Content: DB Connection Type: scope Content: Shareable Type: auth
Content: Container 

Now, I'm no expert by any means, but it seems to me that things are
setup correctly, though I realize my JNDI reader servlet is just reading
web.xml. JNDI knows what's up, or seems to, but for some reason I can't
get a valid DataSource to my database.

Any thoughts?  Suggestions?  I can't switch databases, and I can't buy
another Type 4 driver (the Microsoft driver is free), nor can I use the
JDBC-ODBC bridge.  Any help is appreciated!!

- John


John Turner
[EMAIL PROTECTED] | 248-488-3466
Advertising Audit Service
http://www.aas.com


- John


John Turner

RE: JNDI and/or pooling help (long post)

2002-07-12 Thread Andrew Conrad

Also, check your URL. The syntax is also UserName (case-insensitive) 

Here's my working resource:

ResourceParams name=jdbc/DataStorage
 parameter
  nameurl/name
  valuejdbc:microsoft:sqlserver://localhost:1433/value
 /parameter
 parameter
   namevalidationQuery/name
   valueselect * from organizations/value
 /parameter
 parameter
   namemaxIdle/name
   value2/value
 /parameter
 parameter
   namemaxActive/name
   value10/value
 /parameter
 parameter
   namedriverClassName/name
   valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
 /parameter
 parameter
   namemaxWait/name
   value5000/value
 /parameter
 parameter
   nameusername/name
   valueAndrew/value
 /parameter
 parameter
   namepassword/name
   value12345/value
 /parameter
/ResourceParams

Then, once I get the DataSource, then the connection, I do a
setCatalog() to define the correct DB.

- Andrew

-Original Message-
From: Turner, John [mailto:[EMAIL PROTECTED]] 
Sent: Friday, July 12, 2002 3:37 PM
To: '[EMAIL PROTECTED]'
Subject: JNDI and/or pooling help (long post)



Hello -

I'm having problems getting a connection to my database using JNDI and
various pooling mechanisms. I'm using tomcat 4.0.3 standalone on Win2K.
First, let me say that I can access my database (SQL Server 2000) using
the Microsoft JDBC Type 4 driver without any problems if I put the
connection code right in my servlet (Class.forName, etc.).  If I do
that, no problems. It's only when I try and move the database connection
code up to an application scope or use pooling that I run into problems.
I've setup JNDI according to the Jakarta-Tomcat HOW-TO.

I've tried DBCP/pool according to this link:
http://marc.theaimsgroup.com/?l=tomcat-userm=102225547106556w=2

I also tried the solution from here:
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBo
ok/c
onpool.html

And I also tried the DBConnectionBroker from javaexchange.com, as well
as the DataSourceWrapper/ConnectionPool classes from the O'Reilly JSP
book.

I've even tried setting up DriverName, URL, username, and password as
servlet parameters in web.xml and writing an init servlet that would
read them in, create the datasource, and then push the datasource into
the application scope with getServletContext().setAttribute().  That
didn't work, either.

I would definitely appreciate any help or suggestions, I'm going crazy
trying to figure out what is wrong.  I don't really even need the
pooling, but what I want to do is get the specific database parameters
(username, password, host, etc.) OUT of the servlets (and beans).  I
want other developers to just be able to grab a handle to the
datasource, open a connection, and use it without having to know any
specific information about the database and the parameters.

Here's my server.xml (with the DBCP/pool) setup:

Resource name=jdbc/MyTestDB auth=Container
type=javax.sql.DataSource / ResourceParams name=jdbc/MyTestDB
parameter
  namefactory/name
  valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
/parameter
parameternamemaxActive/namevalue100/value/parameter
parameternamemaxIdle/namevalue3/value/parameter
parameternamemaxWait/namevalue100/value/parameter
parameter
  nameuser/name
  valuesome_user/value
/parameter
parameter
  namepassword/name
  valuesome_password/value
/parameter
parameter
  namedatabasename/name
  valuesome_db/value
/parameter
parameter
  namedriverClassName/name
  valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value
/parameter
parameter
  nameurl/name
 
valuejdbc:microsoft:sqlserver://SOMEHOST:1433;User=some_user;Password=
some
_password;DatabaseName=some_db/value --
/parameter
/ResourceParams

Here is my web.xml:

  resource-ref
descriptionDB Connection/description
res-ref-namejdbc/MyTestDB/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
  /resource-ref

In every case above, regardless of the pooling mechanism, or even just
trying to setup a datasource as an application scope object, I get
either an error message, or null.  In the config above, I get null.  The
code I use with the config above looks like this:

As a test, I wrote a little JNDI reader servlet that just enumerates
over the JNDI space and lists out the objects:

try {
Context initCtx = new InitialContext();
NamingEnumeration enum = initCtx.listBindings(java:comp/env/jdbc);

while (enum.hasMore()) {
Binding binding = (Binding) enum.next();
out.println(Name:  + binding.getName() + br);
out.println(Type:  + binding.getClassName() + br);
out.println(Value:  + binding.getObject() + br);
out.println();
out.println();
}
} catch (NamingException e) {
out.println(Naming Exception:  + e.getMessage());