Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JNDI, ConnectionPool, Tomcat, error: No suitable driver

6 views
Skip to first unread message

Petr Soudek

unread,
Apr 9, 2002, 7:39:48 PM4/9/02
to
Please could anyone give me an idea what I have wrong? I have spent long
time trying but I'm not able to find the solution.

Thank you in advance

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

out.println("datasource:"+ds);

returns the proper name (test jdbc/petrDB)
taken from web.xml
<resource-ref>
<description>test jdbc/petrDB</description>
...

BUT there is next error
at line:
Connection con = ds.getConnection();
error: java.sql.SQLException: No suitable driver

If you have ANY idea please let me know.

Direct code works properly
----------------------------------------------------------------------------
------
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
String url =
"jdbc:microsoft:sqlserver://parallel00;user=test1;Password=testa;DatabaseNam
e=petr_dev1" ;
Connection conDB = null;
Class.forName(driver);
conDB = DriverManager.getConnection(url);


Petr


so I have now this content in my files:
--------------------------------------------------------------------------
-------------------- hello1.jsp
--------------------------------------------------------------------------
<%@page contentType="text/html"%>
<%@page import="java.sql.*"%>
<%@page import="javax.sql.*"%>
<%@page import="javax.naming.Context"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.NamingException"%>
<%@page import="com.microsoft.jdbcx.sqlserver.SQLServerDataSource"%>


<html>
<head><title>JSP Page</title></head>
<body>
test start
<%
out.println("<BR>test<BR>");
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/petrDB");

out.println("datasource:"+ds);

Connection con = ds.getConnection();

--------------------------------------------------------------------------
-------------------- web.xml (located in subdir /WEB-INF of directory where
is hello1.jsp)
--------------------------------------------------------------------------
<resource-ref>
<description>test jdbc/petrDB</description>
<res-ref-name>jdbc/petrDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

--------------------------------------------------------------------------
-------------------- server.xml
--------------------------------------------------------------------------
<Resource name="jdbc/petrDB" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/petrDB">
<parameter>
<name>database</name><value>petr_dev1</value>
</parameter>
<parameter>

<name>driverClassName</name><value>com.microsoft.jdbc.sqlserver.SQLServerDri
ver</value>
</parameter>
<parameter>

<name>driverName</name><value>jdbc:microsoft:sqlserver://parallel00;user=tes
t1;Password=testa;DatabaseName=petr_dev1</value>
</parameter>
<parameter>
<name>user</name><value></value>
</parameter>
<parameter>
<name>password</name><value></value>
</parameter>
</ResourceParams>


Petr Soudek

unread,
Apr 10, 2002, 12:22:58 PM4/10/02
to
This piece of code seems to be working, but I'm not sure if it is correct

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

ConnectionPoolDataSource ds =
(ConnectionPoolDataSource)envCtx.lookup("jdbc/petrDB");
PooledConnection x = ds.getPooledConnection("usr","pwd");
Connection conDB1 = x.getConnection();

Sridhar Paladugu[MS]

unread,
Apr 10, 2002, 9:47:31 AM4/10/02
to
Hi,

You need to create datasource using
com.microsoft.jdbcx.sqlserver.SQLServerDataSource class.
Thanks,

Sridhar Paladugu
Microsoft Developer Support
JDBC Webdata


This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Strategic Technology Protection
Program and to order
your FREE Security Tool Kit, please visit
<http://www.microsoft.com/security>.


Sean LeBlanc

unread,
Apr 17, 2002, 11:43:41 AM4/17/02
to

"Sridhar Paladugu[MS]" <sr...@online.microsoft.com> wrote in message
news:rWwv7LL4BHA.632@cpmsftngxa08...

On the line where I'm trying to do the lookup:

com.microsoft.jdbcx.sqlserver.SQLServerDataSource ds =
(com.microsoft.jdbcx.sqlserver.SQLServerDataSource)envCtx.lookup("jdbc/nutro
sDB");

I get this error:

javax.naming.NamingException: Cannot create resource instance
at
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.
java:167)
at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:299)
at org.apache.naming.NamingContext.lookup(NamingContext.java:834)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)


Any idea on things to check? Here is the whole code snippet:

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

System.out.println(" About to get ds.");
com.microsoft.jdbcx.sqlserver.SQLServerDataSource ds =
(com.microsoft.jdbcx.sqlserver.SQLServerDataSource)envCtx.lookup("jdbc/nutro
sDB");
System.out.println("About to get pooledconnection.");


PooledConnection x = ds.getPooledConnection("usr","pwd");

System.out.println("About to get connection.");
Connection conDB1 = x.getConnection();


Rory Winston

unread,
Apr 18, 2002, 8:30:31 AM4/18/02
to
Hi,

I have the same problems , and I've noticed a couple of interesting
things:

1) Tomcat seems to be passing in the JDBC resources fine, it's only
when you actually do a lookup() that it returns NULL. This *seems* to
imply that it may be a CLASSPATH issue (perhaps?)

2) Tomcat seems to behave slightly differently depending on how you
start it up - if you start it up using the shortcut to the
bootstrap.jar, it doesnt raise a naming excaption, but if you just run
startup.bat, it does (this is what happens on my setup - I know Im
missing a fundamental understanding of how the whole thing works
including CLASSPATH issues, but hey Im new to this :-) )

3) If you run Tomcat in JDB, you can see the boot and working
classpath and visible classes. It would be helpful if someone who has
it working could do this, and we can compare it with our setups. Just
run catalina -debug from the /bin directory.

Ive been wrestling with this for a while, I _think_ that I've got it
narrowed down to CLASSPATH issues, but I'm still not sure .... anyone
else got this working?

Cheers
Rory

"Sean LeBlanc" <se...@nutros.com> wrote in message news:<ejhPfai5BHA.1892@tkmsftngp04>...

Sean LeBlanc

unread,
Apr 18, 2002, 11:08:32 AM4/18/02
to

"Rory Winston" <rory.w...@telewest.co.uk> wrote in message
news:22e0c051.0204...@posting.google.com...

> Hi,
>
> I have the same problems , and I've noticed a couple of interesting
> things:
>
> 1) Tomcat seems to be passing in the JDBC resources fine, it's only
> when you actually do a lookup() that it returns NULL. This *seems* to
> imply that it may be a CLASSPATH issue (perhaps?)
>
> 2) Tomcat seems to behave slightly differently depending on how you
> start it up - if you start it up using the shortcut to the
> bootstrap.jar, it doesnt raise a naming excaption, but if you just run
> startup.bat, it does (this is what happens on my setup - I know Im
> missing a fundamental understanding of how the whole thing works
> including CLASSPATH issues, but hey Im new to this :-) )
>
> 3) If you run Tomcat in JDB, you can see the boot and working
> classpath and visible classes. It would be helpful if someone who has
> it working could do this, and we can compare it with our setups. Just
> run catalina -debug from the /bin directory.
>
> Ive been wrestling with this for a while, I _think_ that I've got it
> narrowed down to CLASSPATH issues, but I'm still not sure .... anyone
> else got this working?


On the Tomcat mailing list, someone had suggested putting this in the
server.xml, along with other Resource info:

<parameter>

<name>factory</name><value>com.microsoft.jdbcx.sqlserver.SQLServerDataSource
Factory</value>
</parameter>


Also, in web.xml, this was something that was suggested. Embedded inside the
resource-ref:
<res-type>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</res-type>

Of course, I still don't have it working, and the error message hasn't
changed at all, so take it with a large grain of salt...


As for CLASSPATH stuff, I just have ms*.jar tacked on in the startup shell
script...I had to do that for the "vanilla connect" to work, so I would hope
that Tomcat would be able to do lookup with this same info in CLASSPATH. I
put the javax extension jar in my /jre/lib/ext/ dir, do you have it set up
the same way?

Rory Winston

unread,
Apr 22, 2002, 6:02:00 AM4/22/02
to
Hi,

Yes, I have the MS .jar files in $JAVA_HOME/jre/lib/ext - I've tried
putting the .jar files in various places , but no joy - I'll give your
suggestion a go and see if it makes any difference.

Cheers
rory

"Sean LeBlanc" <se...@nutros.com> wrote in message news:<uKpbJru5BHA.2116@tkmsftngp04>...

Olegs Denisovs

unread,
Apr 22, 2002, 8:08:12 AM4/22/02
to
i tried to write some time ago that there is an error when you try to use:
com.microsoft.jdbcx.sqlserver.SQLServerDataSourceFactory
and that this class (as it seems to me) can not work as should, if you will
try to dig into code you will find that getDriverName returns not
SQLServerDataSource, as it should but something different
so you can not create data source using factory, i saw it in beta 2. it
seems that for MS it is too hard to change 4 to 3. i would advice avoid
factory, until release or next beta.


"Rory Winston" <rory.w...@telewest.co.uk> wrote in message

news:22e0c051.02042...@posting.google.com...

Sean LeBlanc

unread,
Apr 23, 2002, 12:50:19 PM4/23/02
to

"Olegs Denisovs" <OlegsD...@RobertsonBlums.lv> wrote in message
news:uq1$saf6BHA.2516@tkmsftngp04...

> i tried to write some time ago that there is an error when you try to use:
> com.microsoft.jdbcx.sqlserver.SQLServerDataSourceFactory
> and that this class (as it seems to me) can not work as should, if you
will
> try to dig into code you will find that getDriverName returns not
> SQLServerDataSource, as it should but something different
> so you can not create data source using factory, i saw it in beta 2. it
> seems that for MS it is too hard to change 4 to 3. i would advice avoid
> factory, until release or next beta.

Okay, but what do you suggest as a replacement? If I try just
com.microsoft.jdbcx.sqlserver.SQLServerDataSource in my web.xml (Factory
wasn't in my code as posted below), I get the same error as posted
previously.

Let me plead with those that have it working under Tomcat to post their
server.xml, their web.xml from context directory, and working code. Thanks!

Olegs Denisovs

unread,
Apr 24, 2002, 3:46:57 AM4/24/02
to
we do not use tomcat facilities, just create pooled data source, set
properties and use it, this newsgroup has lot of samples how to create data
source and bind it to JNDI name


"Sean LeBlanc" <se...@nutros.com> wrote in message

news:uAfWibu6BHA.2156@tkmsftngp07...

Sridhar Paladugu[MS]

unread,
Apr 26, 2002, 7:39:28 PM4/26/02
to
Hi all,

I have not understood what tomcat is doing with driver. I have tested this
datasource class using openLDAP thru JNDI and successfully bind the datasource
in the directory and used it for our poolmanager(i wrote one to use internal
testing).This has no problem with either weblogic or websphere application
servers. Currently i do not have tomcat installed. I would appriciate if any
one can provide some inputs regarding how tomcat creates datasources and bind
them in its JNDI environment.

Thanks for every one participating in this community.

Olegs Denisovs

unread,
Apr 29, 2002, 3:01:37 AM4/29/02
to
try to create data source using SQLServerDataSourceFactory, and you will get
an error.

"Sridhar Paladugu[MS]" <sr...@online.microsoft.com> wrote in message

news:zGE1euX7BHA.1700@cpmsftngxa07...

Olegs Denisovs

unread,
Apr 30, 2002, 8:09:33 AM4/30/02
to
i tried to find something bad in tomcat, but it seems everything is fine,
probably just error in documentation, just try to create data source using
factory calling factory and constructing your own reference object, and you
will find that it does not work, just because data source name should match
factory name, unfortunately there is an error in your jdbc driver source and
these names are always different.


"Sridhar Paladugu[MS]" <sr...@online.microsoft.com> wrote in message

news:g52Kzu77BHA.1532@cpmsftngxa08...
> Hi,
>
> I have looked in to tomcat documents and i found that tocat is sending the
> SQLServerDataSourceFactory name as Reference object. Which i believe wrong
for
> this driver.
>
> let us consider my server.xml file is as follows;
>
> <ResourceName="jdbc/northwind" auth=Container"
> type="javax.sql.SQLServerDataSource">
> <ResourceParams name="jdbc/northwind">


>
>
<parameter><name>factory</name><value>com.microsoft.jdbcx.sqlserver.SQLServe
rDat

> aSourceFactory</value></parameter>
>
>
<parameter><name>driverClassName</name><value>com.microsoft.jdbcx.sqlserver.
SQLS
> erverDataSource</value></parameter>
>
<parameter>name>serverName</name><value>wdserver</value></parameter>
> <parameter>name>portNumber</name><value>1433</value></parameter>
>
<parameter>name>databaseName</name><value>pubs</value></parameter>
> <parameter>name>user</name><value>sridhar</value></parameter>
>
<parameter>name>password</name><value>password</value></parameter>
>
<parameter>name>selectMethod</name><value>cursor</value></parameter>
> </ResourceParams>
>
>
> So when we try to create the datasource by calling lookup method, the
tomcat
> context is calling the
>
> SQLServerDataSource.getObjectInstance(Object obj, Name name, Context ctx,
> Hashtable env) ; method using the following values;
>
> obj =
com.microsoft.jdbcx.sqlserver.SQLServerDataSourceFactory
> , but the driverfactory class expecting the obj value as
> com.microsoft.sqlServer.SQLServerDataSource object reference. Since the
> Reference does not match the driver factory is returning the null object.
>
>
> The sample code which is doing this inside driver factory is;
>
> Reference reference = (Reference)obj; //here it is getting
the
> wrong value
>
>
if(reference.getClassName().equals("com.microsoft.jdbcx.sqlserver.SQLServerD
ataS
> ource))
> {
> //create new SQLServerDataSource object;
> loadDataSourceAttributes(reference, newdatasourceobject);
> }
> return basedatasource;
>
> since the above if condition fails the you are recieving a null object.
>
> This behaviour is implemented based on the java spec.
> Look for 4th point in the java class doc javax.naming.spi.ObjectFactory
> (4. If obj is of any other type, the behavior of getObjectInstance() is
> determined by the context factory implementation)
>
> So if the tomcat context send the driverName value to the obj parameter
you
> can get the datasource from the context.
>
> Other approach is to write a class which creates the datasource and bind
it to
> the tomcat context and load this calss when server starts. I used this
approach
> and able to bind datasource to tomcat context.
>
> I am attaching the sample code which i used to bind datasource. Please
have a
> look into that class.
>
>
> This is my view on the tomcat datasource. Any ideas and information is
greately
> appriciated.

Sridhar Paladugu[MS]

unread,
May 2, 2002, 3:00:46 PM5/2/02
to
Please refere to my posting "Steps for settingup datasource in Tomcat4.0 using
SQLServerDatasource."
0 new messages